Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CF-00004/CF-00005 케이스 핸들링 #47

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: CF-00004/CF-00005 케이스 Exception Handling
  • Loading branch information
h-beeen committed Dec 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1d3ea665fbcde7e70b9012a81ce9c890962fe712
3 changes: 3 additions & 0 deletions src/main/java/io/codef/api/constants/CodefReferenceUrl.java
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ public enum CodefReferenceUrl {
TECH_INQUIRY("https://codef.io/cs/inquiry"),
MULTIPLE_REQUEST("https://developer.codef.io/common-guide/multiple-requests"),

WIKI_002(
"https://github.com/codef-io/easycodef-java-v2/wiki/002.-%EC%8B%9C%ED%81%AC%EB%A6%BF-%ED%82%A4-%EA%B8%B0%EB%B0%98-EasyCodef-%EA%B0%9D%EC%B2%B4-%EC%83%9D%EC%84%B1"
),
WIKI_003(
"https://github.com/codef-io/easycodef-java-v2/wiki/003.-%EC%83%81%ED%92%88-%EC%9A%94%EC%B2%AD-%EA%B0%9D%EC%B2%B4-%EC%83%9D%EC%84%B1"
),
4 changes: 4 additions & 0 deletions src/main/java/io/codef/api/constants/CodefResponseCode.java
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@
public class CodefResponseCode {

public static final String CF_00000 = "CF-00000";
public static final String CF_00004 = "CF-00004";
public static final String CF_00005 = "CF-00005";

public static final String CF_03002 = "CF-03002";
public static final String CF_12872 = "CF-12872";

}
110 changes: 59 additions & 51 deletions src/main/java/io/codef/api/error/CodefError.java
Original file line number Diff line number Diff line change
@@ -4,100 +4,108 @@

public enum CodefError {
INVALID_CLIENT_ID(
"clientId must be a properly formatted UUID string. Please check your clientId and ensure it matches the UUID format.",
CodefReferenceUrl.KEY
"clientId must be a properly formatted UUID string. Please check your clientId and ensure it matches the UUID format.",
CodefReferenceUrl.KEY
),
INVALID_CLIENT_SECRET(
"clientSecret must be a properly formatted UUID string. Please check your clientSecret and ensure it matches the UUID format.",
CodefReferenceUrl.KEY
"clientSecret must be a properly formatted UUID string. Please check your clientSecret and ensure it matches the UUID format.",
CodefReferenceUrl.KEY
),
NULL_CLIENT_ID(
"clientId is required and cannot be null.",
CodefReferenceUrl.KEY
"clientId is required and cannot be null.",
CodefReferenceUrl.KEY
),
NULL_CLIENT_SECRET(
"clientSecret is required and cannot be null.",
CodefReferenceUrl.KEY
"clientSecret is required and cannot be null.",
CodefReferenceUrl.KEY
),
NULL_PUBLIC_KEY(
"publicKey is required and cannot be null.",
CodefReferenceUrl.KEY
"publicKey is required and cannot be null.",
CodefReferenceUrl.KEY
),
NULL_CLIENT_TYPE(
"clientType is required and cannot be null.",
CodefReferenceUrl.KEY
"clientType is required and cannot be null.",
CodefReferenceUrl.KEY
),
NULL_ORGANIZATION(
"organization is required and cannot be null.",
CodefReferenceUrl.DEV_GUIDE_REST_API
"organization is required and cannot be null.",
CodefReferenceUrl.DEV_GUIDE_REST_API
),
OAUTH_UNAUTHORIZED(
"Failed to authenticate with the Codef OAuth server (401 Unauthorized). Please verify your clientId and clientSecret values.",
CodefReferenceUrl.KEY
"Failed to authenticate with the Codef OAuth server (401 Unauthorized). Please verify your clientId and clientSecret values.",
CodefReferenceUrl.KEY
),
CODEF_API_UNAUTHORIZED(
"Failed to authenticate with the Codef API server (401 Unauthorized). Please verify your clientId and clientSecret values.",
CodefReferenceUrl.KEY
"Failed to authenticate with the Codef API server (401 Unauthorized). Please verify your clientId and clientSecret values.",
CodefReferenceUrl.KEY
),
OAUTH_INTERNAL_ERROR(
"An error occurred on the Codef OAuth server. Please try again later, or contact support if the issue persists.",
CodefReferenceUrl.KEY
"An error occurred on the Codef OAuth server. Please try again later, or contact support if the issue persists.",
CodefReferenceUrl.KEY
),
OAUTH_CONNECTION_ERROR(
"The connection to the OAUTH server failed. Please check if `https://oauth.codef.io` is accessible.",
CodefReferenceUrl.DEV_GUIDE_REST_API
"The connection to the OAUTH server failed. Please check if `https://oauth.codef.io` is accessible.",
CodefReferenceUrl.DEV_GUIDE_REST_API
),
CODEF_API_SERVER_ERROR(
"An error occurred during the request codef API Product. Please refer to the error message for details.",
CodefReferenceUrl.DEV_GUIDE_REST_API
"An error occurred during the request codef API Product. Please refer to the error message for details.",
CodefReferenceUrl.DEV_GUIDE_REST_API
),
RSA_ENCRYPTION_ERROR(
"An error occurred on RSA Encryption. Please check your publicKey",
CodefReferenceUrl.KEY
"An error occurred on RSA Encryption. Please check your publicKey",
CodefReferenceUrl.KEY
),
NEED_TO_SECURE_WITH_METHOD(
"To encrypt the parameters, you must call the following method: EasyCodefRequestBuilder.builder().secureWith(easyCodef).",
CodefReferenceUrl.GITHUB
"To encrypt the parameters, you must call the following method: EasyCodefRequestBuilder.builder().secureWith(easyCodef).",
CodefReferenceUrl.GITHUB
),
NEED_TO_PATH_METHOD(
"To request codef product, you must call the following method: EasyCodefRequestBuilder.builder().path(\"/v1/kr/***/***...\").",
CodefReferenceUrl.GITHUB
"To request codef product, you must call the following method: EasyCodefRequestBuilder.builder().path(\"/v1/kr/***/***...\").",
CodefReferenceUrl.GITHUB
),
NEED_TO_ORGANIZATION_METHOD(
"To request codef product, you must call the following method: EasyCodefRequestBuilder.builder().organization(\"0xxx\").",
CodefReferenceUrl.GITHUB
"To request codef product, you must call the following method: EasyCodefRequestBuilder.builder().organization(\"0xxx\").",
CodefReferenceUrl.GITHUB
),
INVALID_PATH_REQUESTED(
"The path should be requested in the following format: `/v1/kr/***/***/...`",
CodefReferenceUrl.PRODUCT
"The path should be requested in the following format: `/v1/kr/***/***/...`",
CodefReferenceUrl.PRODUCT
),
INTERNAL_SERVER_ERROR(
"An error occurred on your request.",
CodefReferenceUrl.DEV_GUIDE_REST_API
"An error occurred on your request.",
CodefReferenceUrl.DEV_GUIDE_REST_API
),
PARSE_ERROR(
"An exception occurred because the client could not parse the server response in the expected format, possibly due to incorrect headers or body format.",
CodefReferenceUrl.TECH_INQUIRY
"An exception occurred because the client could not parse the server response in the expected format, possibly due to incorrect headers or body format.",
CodefReferenceUrl.TECH_INQUIRY
),
IO_ERROR(
"An error occurred because the request was either not sent properly or not received. Please check if the outbound port to IP: 211.55.34.5, PORT: 443 is open.",
CodefReferenceUrl.TECH_INQUIRY
"An error occurred because the request was either not sent properly or not received. Please check if the outbound port to IP: 211.55.34.5, PORT: 443 is open.",
CodefReferenceUrl.TECH_INQUIRY
),
SIMPLE_AUTH_FAILED(
"No initial request data is saved for the specified transaction ID.",
CodefReferenceUrl.TECH_INQUIRY
"No initial request data is saved for the specified transaction ID.",
CodefReferenceUrl.TECH_INQUIRY
),
NO_RESPONSE_RECEIVED(
"No responses were received on multiple request",
CodefReferenceUrl.MULTIPLE_REQUEST
"No responses were received on multiple request",
CodefReferenceUrl.MULTIPLE_REQUEST
),
REQUEST_NULL(
"Codef Request Entity is required and cannot be null.",
CodefReferenceUrl.WIKI_003
"Codef Request Entity is required and cannot be null.",
CodefReferenceUrl.WIKI_003
),
TRANSACTION_ID_NULL(
"transactionId is required and cannot be null.",
CodefReferenceUrl.WIKI_005
"transactionId is required and cannot be null.",
CodefReferenceUrl.WIKI_005
),
KEY_CONFLICT_DEMO(
"This token is for the demo version. EasycodefBuilder.clientType(CodefClientType.DEMO)",
CodefReferenceUrl.WIKI_002
),
KEY_CONFLICT_API(
"This token is for the enterprise version. EasycodefBuilder.clientType(CodefClientType.API)",
CodefReferenceUrl.WIKI_002
);


@@ -106,8 +114,8 @@ public enum CodefError {
private final CodefReferenceUrl referenceUrl;

CodefError(
String message,
CodefReferenceUrl referenceUrl
String message,
CodefReferenceUrl referenceUrl
) {
this.message = message;
this.referenceUrl = referenceUrl;
@@ -124,4 +132,4 @@ public String getRawMessage() {
public CodefReferenceUrl getReferenceUrl() {
return referenceUrl;
}
}
}
20 changes: 14 additions & 6 deletions src/main/java/io/codef/api/facade/SingleReqFacade.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import io.codef.api.constants.CodefClientType;
import io.codef.api.dto.EasyCodefRequest;
import io.codef.api.dto.EasyCodefResponse;
import io.codef.api.error.CodefError;
import io.codef.api.error.CodefException;
import io.codef.api.storage.SimpleAuthStorage;

@@ -16,21 +17,28 @@ public class SingleReqFacade {
private final CodefClientType clientType;

public SingleReqFacade(
EasyCodefToken easyCodefToken,
SimpleAuthStorage simpleAuthStorage,
CodefClientType clientType
EasyCodefToken easyCodefToken,
SimpleAuthStorage simpleAuthStorage,
CodefClientType clientType
) {
this.easyCodefToken = easyCodefToken;
this.simpleAuthStorage = simpleAuthStorage;
this.clientType = clientType;
}

public EasyCodefResponse requestProduct(EasyCodefRequest request) throws CodefException {
public EasyCodefResponse requestProduct(
EasyCodefRequest request
) throws CodefException {
String requestUrl = buildRequestUrl(request);
EasyCodefToken validToken = easyCodefToken.validateAndRefreshToken();

EasyCodefResponse response =
EasyCodefConnector.requestProduct(request, validToken, requestUrl);
EasyCodefResponse response = EasyCodefConnector.requestProduct(request, validToken, requestUrl);

if (response.code().equals("CF-00004")) {
throw CodefException.from(CodefError.KEY_CONFLICT_DEMO);
} else if (response.code().equals("CF-00005")) {
throw CodefException.from(CodefError.KEY_CONFLICT_API);
}

simpleAuthStorage.storeIfAddAuthResponse(request, response, requestUrl);
EasyCodefLogger.logResponseStatus(response);