File tree 3 files changed +64
-7
lines changed
src/main/java/com/meilisearch/sdk/Exceptions
3 files changed +64
-7
lines changed Original file line number Diff line number Diff line change 1
- package com .meilisearch .sdk ;
1
+ package com .meilisearch .sdk .exceptions ;
2
+
3
+ import com .meilisearch .sdk .json .GsonJsonHandler ;
2
4
3
5
public class MeiliSearchApiException extends MeiliSearchException {
4
6
7
+ /**
8
+ * This is class wraps errors sent by MeiliSearch API
9
+ */
10
+
11
+ private GsonJsonHandler gson = new GsonJsonHandler ();
12
+
13
+ private class ApiError {
14
+ public String message ;
15
+ public String errorCode ;
16
+ public String errorType ;
17
+ public String errorLink ;
18
+ }
19
+
20
+ public MeiliSearchApiException (String errorMessage ) throws Exception {
21
+ super (errorMessage );
22
+ ApiError error = this .gson .decode (
23
+ errorMessage ,
24
+ ApiError .class
25
+ );
26
+ this .setErrorMessage (error .message );
27
+ this .setErrorCode (error .errorCode );
28
+ this .setErrorType (error .errorType );
29
+ this .setErrorLink (error .errorLink );
30
+ }
31
+
32
+ public String toString () {
33
+ return this .getClass ().getName ()
34
+ + ". Error message: " + this .errorMessage
35
+ + ". Error code: " + this .errorCode
36
+ + ". Error documentation: " + this .errorLink
37
+ + ". Error type: " + this .errorType
38
+ + "." ;
39
+ }
5
40
}
Original file line number Diff line number Diff line change 1
- package com .meilisearch .sdk ;
1
+ package com .meilisearch .sdk . exceptions ;
2
2
3
3
public class MeiliSearchCommunicationException extends MeiliSearchException {
4
4
5
+ public MeiliSearchCommunicationException (String errorMessage ) {
6
+ super (errorMessage );
7
+ }
8
+
5
9
}
Original file line number Diff line number Diff line change 1
- package com .meilisearch .sdk ;
1
+ package com .meilisearch .sdk . exceptions ;
2
2
3
3
public class MeiliSearchException extends Exception {
4
4
5
5
/**
6
6
* This is a generic class for MeiliSearch Exception handling
7
7
*/
8
8
9
- String message ;
9
+ String errorMessage ;
10
+ String errorType ;
10
11
String errorCode ;
11
12
String errorLink ;
12
13
14
+ public MeiliSearchException (String errorMessage ) {
15
+ super (errorMessage );
16
+ this .setErrorMessage (errorMessage );
17
+ }
18
+
13
19
public String getMessage () {
14
- return this .message ;
20
+ return this .errorMessage ;
21
+ }
22
+
23
+ public String getErrorType () {
24
+ return this .errorType ;
15
25
}
16
26
17
27
public String getErrorCode () {
@@ -22,8 +32,12 @@ public String getErrorLink () {
22
32
return this .errorLink ;
23
33
}
24
34
25
- public void setMessage (String message ) {
26
- this .message = message ;
35
+ public void setErrorMessage (String errorMessage ) {
36
+ this .errorMessage = errorMessage ;
37
+ }
38
+
39
+ public void setErrorType (String errorType ) {
40
+ this .errorType = errorType ;
27
41
}
28
42
29
43
public void setErrorCode (String errorCode ) {
@@ -33,4 +47,8 @@ public void setErrorCode (String errorCode) {
33
47
public void setErrorLink (String errorLink ) {
34
48
this .errorLink = errorLink ;
35
49
}
50
+
51
+ public String toString () {
52
+ return this .getClass ().getName () + ". Error message: " + this .errorMessage + "." ;
53
+ }
36
54
}
You can’t perform that action at this time.
0 commit comments