File tree Expand file tree Collapse file tree 3 files changed +64
-7
lines changed
src/main/java/com/meilisearch/sdk/Exceptions Expand file tree Collapse file tree 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 ;
24
35public class MeiliSearchApiException extends MeiliSearchException {
46
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+ }
540}
Original file line number Diff line number Diff line change 1- package com .meilisearch .sdk ;
1+ package com .meilisearch .sdk . exceptions ;
22
33public class MeiliSearchCommunicationException extends MeiliSearchException {
44
5+ public MeiliSearchCommunicationException (String errorMessage ) {
6+ super (errorMessage );
7+ }
8+
59}
Original file line number Diff line number Diff line change 1- package com .meilisearch .sdk ;
1+ package com .meilisearch .sdk . exceptions ;
22
33public class MeiliSearchException extends Exception {
44
55 /**
66 * This is a generic class for MeiliSearch Exception handling
77 */
88
9- String message ;
9+ String errorMessage ;
10+ String errorType ;
1011 String errorCode ;
1112 String errorLink ;
1213
14+ public MeiliSearchException (String errorMessage ) {
15+ super (errorMessage );
16+ this .setErrorMessage (errorMessage );
17+ }
18+
1319 public String getMessage () {
14- return this .message ;
20+ return this .errorMessage ;
21+ }
22+
23+ public String getErrorType () {
24+ return this .errorType ;
1525 }
1626
1727 public String getErrorCode () {
@@ -22,8 +32,12 @@ public String getErrorLink () {
2232 return this .errorLink ;
2333 }
2434
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 ;
2741 }
2842
2943 public void setErrorCode (String errorCode ) {
@@ -33,4 +47,8 @@ public void setErrorCode (String errorCode) {
3347 public void setErrorLink (String errorLink ) {
3448 this .errorLink = errorLink ;
3549 }
50+
51+ public String toString () {
52+ return this .getClass ().getName () + ". Error message: " + this .errorMessage + "." ;
53+ }
3654}
You can’t perform that action at this time.
0 commit comments