From 09b7b0606417848619197ac99ed10ed971726fdd Mon Sep 17 00:00:00 2001 From: furkanozmen Date: Mon, 29 Dec 2025 14:09:11 +0300 Subject: [PATCH 1/3] add provider error response --- src/CraftgateError.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/CraftgateError.ts b/src/CraftgateError.ts index 03a4373..fcdeb42 100644 --- a/src/CraftgateError.ts +++ b/src/CraftgateError.ts @@ -1,18 +1,26 @@ +type ProviderError = { + errorCode?: string; + errorMessage?: string; +}; + type ErrorResponse = { errorCode: string; errorDescription: string; + providerError?: ProviderError; }; export default class CraftgateError extends Error { private _errorCode: string; private _errorDescription: string; + private _providerError?: ProviderError; private _errorData: any; - constructor({errorCode, errorDescription, ...rest}: ErrorResponse) { + constructor({ errorCode, errorDescription, providerError, ...rest }: ErrorResponse) { super(errorDescription); this._errorCode = errorCode; this._errorDescription = errorDescription; + this._providerError = providerError; this._errorData = rest; Object.setPrototypeOf(this, CraftgateError.prototype); @@ -26,7 +34,20 @@ export default class CraftgateError extends Error { return this._errorDescription; } + getProviderError(): ProviderError | undefined { + return this._providerError; + } + getErrorData(): any { return this._errorData; } + + toString(): string { + let message = `CraftgateError: ${this._errorCode} - ${this._errorDescription}`; + if (this._providerError) { + message += ` (Provider: ${this._providerError.errorCode} - ${this._providerError.errorMessage})`; + } + return message; + } } + From a190fe3da6013cc8a9631eee378df8302e0ebced Mon Sep 17 00:00:00 2001 From: furkanozmen Date: Mon, 29 Dec 2025 14:12:24 +0300 Subject: [PATCH 2/3] remove unused toString method --- src/CraftgateError.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/CraftgateError.ts b/src/CraftgateError.ts index fcdeb42..9e03e50 100644 --- a/src/CraftgateError.ts +++ b/src/CraftgateError.ts @@ -41,13 +41,4 @@ export default class CraftgateError extends Error { getErrorData(): any { return this._errorData; } - - toString(): string { - let message = `CraftgateError: ${this._errorCode} - ${this._errorDescription}`; - if (this._providerError) { - message += ` (Provider: ${this._providerError.errorCode} - ${this._providerError.errorMessage})`; - } - return message; - } } - From c77add11cb489349e84e1c1f748293514b76946f Mon Sep 17 00:00:00 2001 From: furkanozmen Date: Mon, 29 Dec 2025 14:15:09 +0300 Subject: [PATCH 3/3] formatted code --- src/CraftgateError.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CraftgateError.ts b/src/CraftgateError.ts index 9e03e50..cb763f9 100644 --- a/src/CraftgateError.ts +++ b/src/CraftgateError.ts @@ -15,7 +15,7 @@ export default class CraftgateError extends Error { private _providerError?: ProviderError; private _errorData: any; - constructor({ errorCode, errorDescription, providerError, ...rest }: ErrorResponse) { + constructor({errorCode, errorDescription, providerError, ...rest}: ErrorResponse) { super(errorDescription); this._errorCode = errorCode;