@@ -35,7 +35,7 @@ final void handle(@NotNull ApiServer.Request request) {
3535 JsonElement result = handleRequest (request );
3636 request .answerResult (result );
3737 } catch (HandlingException ex ) {
38- request .answerError (ex .code , ex .msg , ex .data );
38+ request .answerError (ex .code . code , ex .msg , ex .data );
3939 } catch (ApiServer .PredefinedJsonRpcException ex ) {
4040 request .answerError (ex );
4141 }
@@ -46,30 +46,41 @@ final void handle(@NotNull ApiServer.Request request) {
4646
4747 protected abstract void handleNotification (@ NotNull ApiServer .Request request );
4848
49+ public enum ErrorCode {
50+ MERCURY_EXCEPTION (1001 ),
51+ IO_EXCEPTION (1002 );
52+
53+ public final int code ;
54+
55+ ErrorCode (int code ) {
56+ this .code = code ;
57+ }
58+ }
59+
4960 protected static class HandlingException extends Exception {
50- private final int code ;
61+ private final ErrorCode code ;
5162 private final String msg ;
5263 private final JsonElement data ;
5364
54- public HandlingException (int code , @ NotNull String msg , @ Nullable JsonElement data ) {
65+ public HandlingException (@ NotNull ErrorCode code , @ NotNull String msg , @ Nullable JsonElement data ) {
5566 super (msg );
5667 this .code = code ;
5768 this .msg = msg ;
5869 this .data = data ;
5970 }
6071
61- public HandlingException (int code , @ NotNull String msg ) {
72+ public HandlingException (@ NotNull ErrorCode code , @ NotNull String msg ) {
6273 this (code , msg , null );
6374 }
6475
65- public HandlingException (@ NotNull Throwable cause , int code , @ Nullable JsonElement data ) {
76+ public HandlingException (@ NotNull Throwable cause , @ NotNull ErrorCode code , @ Nullable JsonElement data ) {
6677 super (cause );
6778 this .code = code ;
6879 this .msg = cause .getMessage ();
6980 this .data = data ;
7081 }
7182
72- public HandlingException (@ NotNull Throwable cause , int code ) {
83+ public HandlingException (@ NotNull Throwable cause , @ NotNull ErrorCode code ) {
7384 this (cause , code , null );
7485 }
7586 }
0 commit comments