Skip to content
18 changes: 18 additions & 0 deletions src/main/java/io/craftgate/exception/CraftgateException.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,43 @@ public class CraftgateException extends RuntimeException {
private final String errorCode;
private final String errorDescription;
private final String errorGroup;
private final String providerErrorCode;
private final String providerErrorDescription;

public CraftgateException() {
super(GENERAL_ERROR_DESCRIPTION);
this.errorCode = GENERAL_ERROR_CODE;
this.errorDescription = GENERAL_ERROR_DESCRIPTION;
this.errorGroup = GENERAL_ERROR_GROUP;
this.providerErrorCode = null;
this.providerErrorDescription = null;
}

public CraftgateException(String errorCode, String errorDescription, String errorGroup) {
super(errorDescription);
this.errorCode = errorCode;
this.errorDescription = errorDescription;
this.errorGroup = errorGroup;
this.providerErrorCode = null;
this.providerErrorDescription = null;
}

public CraftgateException(String errorCode, String errorDescription, String errorGroup,
String providerErrorCode, String providerErrorDescription) {
super(errorDescription);
this.errorCode = errorCode;
this.errorDescription = errorDescription;
this.errorGroup = errorGroup;
this.providerErrorCode = providerErrorCode;
this.providerErrorDescription = providerErrorDescription;
}

public CraftgateException(Throwable cause) {
super(cause.getMessage(), cause);
this.errorCode = GENERAL_ERROR_CODE;
this.errorDescription = GENERAL_ERROR_DESCRIPTION;
this.errorGroup = GENERAL_ERROR_GROUP;
this.providerErrorCode = null;
this.providerErrorDescription = null;
}
}
11 changes: 10 additions & 1 deletion src/main/java/io/craftgate/net/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ private static <T> void requireSuccess(HttpResponse httpResponse, Class<T> respo
response = gson.fromJson(new String(httpResponse.getBody(), StandardCharsets.UTF_8), Response.class);
if (response != null && response.getErrors() != null) {
ErrorResponse errors = response.getErrors();
throw new CraftgateException(errors.getErrorCode(), errors.getErrorDescription(), errors.getErrorGroup());
if (errors.getProviderError() != null) {
throw new CraftgateException(
errors.getErrorCode(),
errors.getErrorDescription(),
errors.getErrorGroup(),
errors.getProviderError().getErrorCode(),
errors.getProviderError().getErrorMessage());
}
throw new CraftgateException(errors.getErrorCode(), errors.getErrorDescription(),
errors.getErrorGroup());
}
throw new CraftgateException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public class ErrorResponse {
private String errorCode;
private String errorDescription;
private String errorGroup;
private ProviderError providerError;
}
10 changes: 10 additions & 0 deletions src/main/java/io/craftgate/response/common/ProviderError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.craftgate.response.common;

import lombok.Data;

@Data
public class ProviderError {

private String errorCode;
private String errorMessage;
}