Skip to content

Commit

Permalink
Add credential disabled error
Browse files Browse the repository at this point in the history
  • Loading branch information
phieronymus committed Feb 16, 2021
1 parent d0478fb commit 771cfe7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/errors/APIError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,16 @@ export enum ResponseErrorCode {

/* gateway credentials */
CredentialsExist = "CREDENTIALS_EXISTS",
GatewayConfigurationRequired = "GATEWAY_CONFIGURATION_REQUIRED",

/* Gateway simulation */
PlatformCredentialsDisabled = "PLATFORM_CREDENTIALS_DISABLED",

/* Refund */
RefundExceedsChargeAmount = "REFUND_EXCEEDS_CHARGE_AMOUNT",
CannotRefundUnsuccessfulCharge = "CANNOT_REFUND_UNSUCCESSFUL_CHARGE",
RefundNotAllowed = "REFUND_NOT_ALLOWED",
CancelNotAllowed = "CANCEL_NOT_ALLOWED",
GatewayConfigurationRequired = "GATEWAY_CONFIGURATION_REQUIRED",

/* apple pay */
ApplePayNotEnabled = "APPLE_PAY_NOT_ENABLED",
Expand Down
5 changes: 3 additions & 2 deletions src/errors/RequestResponseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ const formatErrors = ({ errors: rawErrors, ...rest }: RawErrorRequest): Formatte
const formattedErrors: (SubError | ValidationError)[] = errorList.filter(Boolean).map((error: ErrorItem) => {
if (typeof error === "string") {
const errorCodeKeys = [...Object.keys(ResponseErrorCode), ...Object.keys(RequestErrorCode)];
const upperCaseError = error.toUpperCase();
const isValidError = errorCodeKeys.some(
(key) => ResponseErrorCode[key] === error || RequestErrorCode[key] === error
(key) => ResponseErrorCode[key] === upperCaseError || RequestErrorCode[key] === upperCaseError
);

return {
reason: isValidError ? (String(error) as ResponseErrorCode) : ResponseErrorCode.UnknownError,
reason: isValidError ? (upperCaseError as ResponseErrorCode) : ResponseErrorCode.UnknownError,
field: null,
};
}
Expand Down

0 comments on commit 771cfe7

Please sign in to comment.