@webpieces/http-client-core 0.4.776 → 0.4.778
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/ClientErrorTranslator.d.ts +1 -0
- package/src/ClientErrorTranslator.js +14 -0
- package/src/ClientErrorTranslator.js.map +1 -1
- package/src/UnexpectedApiResponseError.d.ts +1 -1
- package/src/UnexpectedApiResponseError.js +1 -1
- package/src/UnexpectedApiResponseError.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/http-client-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.778",
|
|
4
4
|
"description": "Isomorphic core of the webpieces HTTP client: the decorator-driven ProxyClient, error translation, and the Proxy trap shared by http-client-node and http-client-browser",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@webpieces/core-util": "0.4.
|
|
24
|
+
"@webpieces/core-util": "0.4.778"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -5,6 +5,7 @@ export declare class ClientErrorTranslator {
|
|
|
5
5
|
static translateError(response: HttpResponseDto): TranslatedFailure;
|
|
6
6
|
/** Semantic body kind is authoritative when it agrees with the HTTP adapter status. */
|
|
7
7
|
static builtInError(response: HttpResponseDto): Error;
|
|
8
|
+
/** Non-Webpieces responders: named statuses map to their class, any other 100-599 to ApiCodedError. */
|
|
8
9
|
private static fromStatus;
|
|
9
10
|
private static fallbackMessage;
|
|
10
11
|
}
|
|
@@ -25,6 +25,7 @@ class ClientErrorTranslator {
|
|
|
25
25
|
}
|
|
26
26
|
return this.fromStatus(response.status.code, this.fallbackMessage(response.body, response.status.reason));
|
|
27
27
|
}
|
|
28
|
+
/** Non-Webpieces responders: named statuses map to their class, any other 100-599 to ApiCodedError. */
|
|
28
29
|
// webpieces-disable no-function-outside-class -- fallback for non-Webpieces HTTP responders
|
|
29
30
|
static fromStatus(statusCode, message) {
|
|
30
31
|
switch (statusCode) {
|
|
@@ -40,10 +41,20 @@ class ClientErrorTranslator {
|
|
|
40
41
|
return new core_util_1.ApiNotFoundError(message);
|
|
41
42
|
case 408:
|
|
42
43
|
return new core_util_1.ApiRequestTimeoutError(message);
|
|
44
|
+
case 409:
|
|
45
|
+
return new core_util_1.ApiConflictError(message);
|
|
46
|
+
case 412:
|
|
47
|
+
return new core_util_1.ApiPreconditionFailedError(message);
|
|
48
|
+
case 415:
|
|
49
|
+
return new core_util_1.ApiUnsupportedMediaTypeError(message);
|
|
50
|
+
case 422:
|
|
51
|
+
return new core_util_1.ApiUnprocessableError(message);
|
|
43
52
|
case 429:
|
|
44
53
|
return new core_util_1.ApiRateLimitedError(message);
|
|
45
54
|
case 500:
|
|
46
55
|
return new core_util_1.ApiImplementationError('Internal Error', undefined, true);
|
|
56
|
+
case 501:
|
|
57
|
+
return new core_util_1.ApiNotImplementedError(message);
|
|
47
58
|
case 502:
|
|
48
59
|
return new core_util_1.ApiDependencyError(message);
|
|
49
60
|
case 503:
|
|
@@ -51,6 +62,9 @@ class ClientErrorTranslator {
|
|
|
51
62
|
case 504:
|
|
52
63
|
return new core_util_1.ApiDependencyTimeoutError(message);
|
|
53
64
|
default:
|
|
65
|
+
// Any other real HTTP status keeps its code; only a value no HTTP status can hold is unexpected.
|
|
66
|
+
if (core_util_1.ApiCodedError.isStatusCode(statusCode))
|
|
67
|
+
return new core_util_1.ApiCodedError(message, statusCode);
|
|
54
68
|
return new UnexpectedApiResponseError_1.UnexpectedApiResponseError(statusCode, message);
|
|
55
69
|
}
|
|
56
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientErrorTranslator.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-core/src/ClientErrorTranslator.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ClientErrorTranslator.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-core/src/ClientErrorTranslator.ts"],"names":[],"mappings":";;;AAAA,oDAsB8B;AAC9B,2DAAwD;AACxD,6EAA0E;AAE1E,yEAAyE;AACzE,MAAa,qBAAqB;IAC9B,mGAAmG;IACnG,MAAM,CAAC,cAAc,CAAC,QAAyB;QAC3C,MAAM,MAAM,GAAG,0BAAc,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,IAAI,qCAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3F,OAAO,IAAI,qCAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC;IAED,uFAAuF;IACvF,kFAAkF;IAClF,MAAM,CAAC,YAAY,CAAC,QAAyB;QACzC,IAAI,yBAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,yBAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACpD,IACI,8BAAkB,CAAC,OAAO,CAAC,OAAO,CAAC;gBACnC,8BAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,MAAM,CAAC,IAAI;gBAEzD,OAAO,OAAO,CAAC;YACnB,OAAO,IAAI,kCAAsB,CAAC,gBAAgB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAClB,QAAQ,CAAC,MAAM,CAAC,IAAI,EACpB,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,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;gBACJ,OAAO,IAAI,qCAAyB,CAAC,OAAO,CAAC,CAAC;YAClD;gBACI,iGAAiG;gBACjG,IAAI,yBAAa,CAAC,YAAY,CAAC,UAAU,CAAC;oBACtC,OAAO,IAAI,yBAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAClD,OAAO,IAAI,uDAA0B,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACnE,CAAC;IACL,CAAC;IAED,kHAAkH;IAClH,iGAAiG;IACzF,MAAM,CAAC,eAAe,CAAC,IAAa,EAAE,MAAc;QACxD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC;YACxE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,MAAM,IAAI,gBAAgB,CAAC;IACtC,CAAC;CACJ;AA/ED,sDA+EC","sourcesContent":["import {\n ApiBadRequestError,\n ApiCodedError,\n ApiConflictError,\n ApiDependencyError,\n ApiDependencyTimeoutError,\n ApiEndUserError,\n ApiErrorCodec,\n ApiForbiddenError,\n ApiImplementationError,\n ApiNotFoundError,\n ApiNotImplementedError,\n ApiPreconditionFailedError,\n ApiRateLimitedError,\n ApiRequestTimeoutError,\n ApiUnauthorizedError,\n ApiUnavailableError,\n ApiUnprocessableError,\n ApiUnsupportedMediaTypeError,\n ClientRegistry,\n ApiErrorHttpStatus,\n HttpResponseDto,\n} from '@webpieces/core-util';\nimport { TranslatedFailure } from './TranslatedFailure';\nimport { UnexpectedApiResponseError } from './UnexpectedApiResponseError';\n\n/** Reconstructs transport-neutral API failures from an HTTP response. */\nexport class ClientErrorTranslator {\n // webpieces-disable no-function-outside-class -- pure stateless mapping shared by browser and node\n static translateError(response: HttpResponseDto): TranslatedFailure {\n const custom = ClientRegistry.tryTranslateFromWire(response);\n if (custom !== undefined) return new TranslatedFailure(custom, true, response.status.code);\n return new TranslatedFailure(this.builtInError(response), false, response.status.code);\n }\n\n /** Semantic body kind is authoritative when it agrees with the HTTP adapter status. */\n // webpieces-disable no-function-outside-class -- public delegable default mapping\n static builtInError(response: HttpResponseDto): Error {\n if (ApiErrorCodec.isPayload(response.body)) {\n const decoded = ApiErrorCodec.decode(response.body);\n if (\n ApiErrorHttpStatus.hasCode(decoded) &&\n ApiErrorHttpStatus.code(decoded) === response.status.code\n )\n return decoded;\n return new ApiImplementationError('Internal Error', undefined, true);\n }\n return this.fromStatus(\n response.status.code,\n this.fallbackMessage(response.body, response.status.reason),\n );\n }\n\n /** Non-Webpieces responders: named statuses map to their class, any other 100-599 to ApiCodedError. */\n // webpieces-disable no-function-outside-class -- fallback for non-Webpieces HTTP responders\n private static fromStatus(statusCode: number, message: string): Error {\n switch (statusCode) {\n case 266:\n return new ApiEndUserError(message);\n case 400:\n return new ApiBadRequestError(message);\n case 401:\n return new ApiUnauthorizedError(message);\n case 403:\n return new ApiForbiddenError(message);\n case 404:\n return new ApiNotFoundError(message);\n case 408:\n return new ApiRequestTimeoutError(message);\n case 409:\n return new ApiConflictError(message);\n case 412:\n return new ApiPreconditionFailedError(message);\n case 415:\n return new ApiUnsupportedMediaTypeError(message);\n case 422:\n return new ApiUnprocessableError(message);\n case 429:\n return new ApiRateLimitedError(message);\n case 500:\n return new ApiImplementationError('Internal Error', undefined, true);\n case 501:\n return new ApiNotImplementedError(message);\n case 502:\n return new ApiDependencyError(message);\n case 503:\n return new ApiUnavailableError(message);\n case 504:\n return new ApiDependencyTimeoutError(message);\n default:\n // Any other real HTTP status keeps its code; only a value no HTTP status can hold is unexpected.\n if (ApiCodedError.isStatusCode(statusCode))\n return new ApiCodedError(message, statusCode);\n return new UnexpectedApiResponseError(statusCode, message);\n }\n }\n\n // webpieces-disable no-any-unknown -- HTTP response bodies are app-owned until this boundary safely inspects them\n // webpieces-disable no-function-outside-class -- bounds diagnostic text from a foreign responder\n private static fallbackMessage(body: unknown, reason: string): string {\n if (typeof body === 'object' && body !== null) {\n const message = Object.getOwnPropertyDescriptor(body, 'message')?.value;\n if (typeof message === 'string' && message.length > 0) return message.slice(0, 4096);\n }\n return reason || 'Request Failed';\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** HTTP adapter failure for
|
|
1
|
+
/** HTTP adapter failure for a status outside 100-599 (so not an ApiCodedError) not claimed by an app translator. */
|
|
2
2
|
export declare class UnexpectedApiResponseError extends Error {
|
|
3
3
|
readonly statusCode: number;
|
|
4
4
|
constructor(statusCode: number, message: string);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnexpectedApiResponseError = void 0;
|
|
4
|
-
/** HTTP adapter failure for
|
|
4
|
+
/** HTTP adapter failure for a status outside 100-599 (so not an ApiCodedError) not claimed by an app translator. */
|
|
5
5
|
class UnexpectedApiResponseError extends Error {
|
|
6
6
|
statusCode;
|
|
7
7
|
constructor(statusCode, message) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnexpectedApiResponseError.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-core/src/UnexpectedApiResponseError.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"UnexpectedApiResponseError.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-core/src/UnexpectedApiResponseError.ts"],"names":[],"mappings":";;;AAAA,oHAAoH;AACpH,MAAa,0BAA2B,SAAQ,KAAK;IAE7B;IADpB,YACoB,UAAkB,EAClC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,eAAU,GAAV,UAAU,CAAQ;QAIlC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC7C,CAAC;CACJ;AARD,gEAQC","sourcesContent":["/** HTTP adapter failure for a status outside 100-599 (so not an ApiCodedError) not claimed by an app translator. */\nexport class UnexpectedApiResponseError extends Error {\n constructor(\n public readonly statusCode: number,\n message: string,\n ) {\n super(message);\n this.name = 'UnexpectedApiResponseError';\n }\n}\n"]}
|