diff options
author | Florian Dold <florian@dold.me> | 2023-12-04 21:16:39 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-12-04 21:16:39 +0100 |
commit | 8a3e6f25ef975e1a3177f73630f866a7b9b214fb (patch) | |
tree | f302eb6394447f8ee082d928b066f689fb3e980a /packages | |
parent | 7f21700576b4de0f5479ea258b75fb141d18a41b (diff) | |
download | wallet-core-8a3e6f25ef975e1a3177f73630f866a7b9b214fb.tar.xz |
report content type if unexpected
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-util/src/errors.ts | 16 | ||||
-rw-r--r-- | packages/taler-util/src/http-common.ts | 1 |
2 files changed, 12 insertions, 5 deletions
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts index cbf4263fc..7439ba69d 100644 --- a/packages/taler-util/src/errors.ts +++ b/packages/taler-util/src/errors.ts @@ -103,6 +103,11 @@ export interface DetailsMap { requestMethod: string; httpStatusCode: number; validationError?: string; + /** + * Content type of the response, usually only specified if not the + * expected content type. + */ + contentType?: string; }; [TalerErrorCode.WALLET_EXCHANGE_COIN_SIGNATURE_INVALID]: empty; [TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE]: { @@ -197,17 +202,19 @@ export class TalerProtocolViolationError extends Error { } // compute a subset of TalerError, just for http request -type HttpErrors = TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT +type HttpErrors = + | TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT | TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED | TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE | TalerErrorCode.WALLET_NETWORK_ERROR | TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR; type TalerHttpErrorsDetails = { - [code in HttpErrors]: TalerError<DetailsMap[code]> -} + [code in HttpErrors]: TalerError<DetailsMap[code]>; +}; -export type TalerHttpError = TalerHttpErrorsDetails[keyof TalerHttpErrorsDetails] +export type TalerHttpError = + TalerHttpErrorsDetails[keyof TalerHttpErrorsDetails]; export class TalerError<T = any> extends Error { errorDetail: TalerErrorDetail & T; @@ -243,7 +250,6 @@ export class TalerError<T = any> extends Error { ): this is TalerError<DetailsMap[C]> { return this.errorDetail.code === code; } - } /** diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts index e934c07f7..7c58b3874 100644 --- a/packages/taler-util/src/http-common.ts +++ b/packages/taler-util/src/http-common.ts @@ -155,6 +155,7 @@ export async function readTalerErrorResponse( requestUrl: httpResponse.requestUrl, requestMethod: httpResponse.requestMethod, httpStatusCode: httpResponse.status, + contentType: contentType || "<null>", }, "Error response did not even contain JSON. The request URL might be wrong or the service might be unavailable.", ); |