-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java sdk): define erro code enums (#77)
* feat(java sdk): define erro code enums Signed-off-by: STRRL <im@strrl.dev> * feat(java sdk): introduce ReddioBusinessException and ReddioServiceException Signed-off-by: STRRL <im@strrl.dev> * test(java sdk): append integration test cases Signed-off-by: STRRL <im@strrl.dev> * feat(java sdk): new error codes Signed-off-by: STRRL <im@strrl.dev> * feat(java sdk): update error codes Signed-off-by: STRRL <im@strrl.dev> * test: update test cases for invalid api key Signed-off-by: STRRL <im@strrl.dev> --------- Signed-off-by: STRRL <im@strrl.dev>
- Loading branch information
Showing
19 changed files
with
454 additions
and
160 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
reddio-java/reddio-api/src/main/java/com/reddio/api/v1/requests/polling/OrderPoller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
reddio-java/reddio-api/src/main/java/com/reddio/api/v1/requests/polling/RecordPoller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ | |
public class TransferResponse { | ||
|
||
@JsonProperty("sequence_id") | ||
public long sequenceId; | ||
public Long sequenceId; | ||
} |
51 changes: 51 additions & 0 deletions
51
reddio-java/reddio-api/src/main/java/com/reddio/exception/ReddioBusinessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.reddio.exception; | ||
|
||
import com.reddio.api.v1.rest.ResponseWrapper; | ||
import jnr.x86asm.RID; | ||
import lombok.Getter; | ||
|
||
|
||
/** | ||
* ReddioBusinessException represents the business exception that return by the reddio service. | ||
*/ | ||
public class ReddioBusinessException extends ReddioException { | ||
private static final long serialVersionUID = -6477748788283734748L; | ||
|
||
/** | ||
* The status in the response. | ||
*/ | ||
@Getter | ||
private final String status; | ||
|
||
/** | ||
* Error message. | ||
*/ | ||
@Getter | ||
private final String error; | ||
|
||
/** | ||
* Error code as enum, might be null if the error code is not recognized. | ||
* <p/> | ||
* You could still get the error code from raw response {@link #getResponse()}. | ||
*/ | ||
@Getter | ||
private final ReddioErrorCode errorCode; | ||
|
||
/** | ||
* Raw response from the reddio service. | ||
*/ | ||
@Getter | ||
private final ResponseWrapper<?> response; | ||
|
||
public ReddioBusinessException(String status, String error, ReddioErrorCode errorCode, ResponseWrapper<?> response) { | ||
this.status = status; | ||
this.error = error; | ||
this.errorCode = errorCode; | ||
this.response = response; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("reddio business failure, status: %s, error: %s, error code: %s", status, error, errorCode); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
reddio-java/reddio-api/src/main/java/com/reddio/exception/ReddioErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.reddio.exception; | ||
|
||
import lombok.Getter; | ||
|
||
public enum ReddioErrorCode { | ||
Success(0), | ||
StarkKeyMissing(1), | ||
AmountInvalid(2), | ||
TokenIDMissing(3), | ||
TokenIDParseFailed(4), | ||
NOSuchAccountID(5), | ||
NoSuchAssetID(6), | ||
NoMintableToken(7), | ||
InsufficientAvailable(8), | ||
InsufficientFrozen(9), | ||
AddSequenceFailed(10), | ||
FailedToGenerateNonce(11), | ||
OrderFormatError(12), | ||
DuplicateTransactionError(13), | ||
FullWithdrawError(14), | ||
NotSuchContract(15), | ||
FailedToGenerateVaultID(16), | ||
CancelOrderWrongOwner(17), | ||
StarkKeyInvalid(18), | ||
InvalidParam(19), | ||
OrderConditionalCanceled(20), | ||
FOKAndIOCCanceled(21), | ||
TokenIDInvalid(22), | ||
MintAmountInvalid(23), | ||
DuplicateOrderInfoError(24), | ||
NotSuchToken(25), | ||
CanceledOrder(26), | ||
ContractAddressMissing(27), | ||
NoSuchContractType(28), | ||
FailedToParseUint(29), | ||
CommandToEventFailed(30), | ||
EventNotMatch(31), | ||
InvalidAPIKey(32), | ||
InvalidOwnerOfContract(33), | ||
FailedToVerifyParams(400), | ||
FailedToJSONUnmarshal(401), | ||
SystemError(500); | ||
|
||
ReddioErrorCode(int code) { | ||
this.code = code; | ||
} | ||
|
||
@Getter | ||
private final int code; | ||
|
||
public static ReddioErrorCode fromCode(Integer code) { | ||
if (code == null) { | ||
return null; | ||
} | ||
for (ReddioErrorCode errorCode : ReddioErrorCode.values()) { | ||
if (errorCode.getCode() == code) { | ||
return errorCode; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
9 changes: 8 additions & 1 deletion
9
...main/java/com/reddio/ReddioException.java → ...com/reddio/exception/ReddioException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
reddio-java/reddio-api/src/main/java/com/reddio/exception/ReddioServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.reddio.exception; | ||
|
||
import lombok.Getter; | ||
|
||
/** | ||
* ReddioServiceException represents the exception when the reddio service not respond successfully. | ||
* | ||
* @author strrl | ||
*/ | ||
public class ReddioServiceException extends ReddioException { | ||
public ReddioServiceException(String description, int httpStatusCode, ReddioErrorCode errorCode, String responseBody) { | ||
this.description = description; | ||
this.httpStatusCode = httpStatusCode; | ||
this.errorCode = errorCode; | ||
this.responseBody = responseBody; | ||
} | ||
|
||
private static final long serialVersionUID = 1205765559865993637L; | ||
|
||
/** | ||
* Description of the exception. | ||
*/ | ||
@Getter | ||
private final String description; | ||
|
||
/** | ||
* Http status code. | ||
*/ | ||
@Getter | ||
private final int httpStatusCode; | ||
|
||
/** | ||
* Error code as enum, might be null if the error code is not recognized. | ||
*/ | ||
@Getter | ||
private final ReddioErrorCode errorCode; | ||
|
||
/** | ||
* The raw response body as string. | ||
*/ | ||
@Getter | ||
private final String responseBody; | ||
|
||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("reddio service not respond service, description: %s, http status code: %d, error code: %s, response body: %s", description, httpStatusCode, errorCode, responseBody); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
reddio-java/reddio-api/src/main/kotlin/com/reddio/api/v1/DefaultReddioClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
reddio-java/reddio-api/src/main/kotlin/com/reddio/api/v1/TransferFailedException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
reddio-java/reddio-api/src/main/kotlin/com/reddio/api/v1/requests/ReddioWithdrawalToApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.