@@ -9,8 +9,8 @@ public class WeaviateApiException extends RuntimeException {
99 private final String errorMessage ;
1010 private final Source source ;
1111 private final String endpoint ;
12- private final Integer statusCode ;
13- private final String grpcStatus ;
12+ private final Integer httpStatusCode ;
13+ private final io . grpc . Status . Code grpcStatusCode ;
1414
1515 private enum Source {
1616 HTTP , GRPC ;
@@ -22,32 +22,48 @@ public static WeaviateApiException http(String method, String endpoint, int stat
2222
2323 public static WeaviateApiException gRPC (io .grpc .StatusRuntimeException ex ) {
2424 var status = ex .getStatus ();
25- return new WeaviateApiException (status .getCode (). toString () , status .getDescription ());
25+ return new WeaviateApiException (status .getCode (), status .getDescription ());
2626 }
2727
28- private WeaviateApiException (String status , String errorMessage ) {
29- super ("%s: %s" .formatted (status , errorMessage ));
28+ private WeaviateApiException (io . grpc . Status . Code code , String errorMessage ) {
29+ super ("%s: %s" .formatted (code , errorMessage ));
3030 this .source = Source .GRPC ;
3131 this .errorMessage = errorMessage ;
32- this .grpcStatus = status ;
32+ this .grpcStatusCode = code ;
3333 this .endpoint = null ;
34- this .statusCode = null ;
34+ this .httpStatusCode = null ;
3535 }
3636
3737 private WeaviateApiException (String method , String endpoint , int statusCode , String errorMessage ) {
3838 super ("HTTP %d: %s %s: %s" .formatted (statusCode , method , endpoint , errorMessage ));
3939 this .source = Source .HTTP ;
4040 this .errorMessage = errorMessage ;
4141 this .endpoint = endpoint ;
42- this .statusCode = statusCode ;
43- this .grpcStatus = null ;
42+ this .httpStatusCode = statusCode ;
43+ this .grpcStatusCode = null ;
44+ }
45+
46+ public boolean isGPRC () {
47+ return source == Source .GRPC ;
48+ }
49+
50+ public String grpcStatusCode () {
51+ return grpcStatusCode .toString ();
52+ }
53+
54+ public boolean isHTTP () {
55+ return source == Source .HTTP ;
4456 }
4557
4658 public String endpoint () {
4759 return endpoint ;
4860 }
4961
50- public Integer statusCode () {
51- return statusCode ;
62+ public Integer httpStatusCode () {
63+ return httpStatusCode ;
64+ }
65+
66+ public String getError () {
67+ return errorMessage ;
5268 }
5369}
0 commit comments