@springworks/error-factory
Advanced tools
Comparing version 3005.23.0 to 3005.34.0
@@ -212,1 +212,26 @@ "use strict"; | ||
}); | ||
describe('createClientErrorForResponse', () => { | ||
it('should create a client error correct parameters if response has the structure of a client error payload', () => { | ||
const error_response = { error: { code: 'something-wrong', message: 'Something wrong' } }; | ||
const response = { | ||
code: 422, | ||
body: error_response, | ||
}; | ||
const client_error = client_error_1.createClientErrorForResponse(response); | ||
expect(client_error.client_http_status_code).toBe(422); | ||
expect(client_error.is_client_error).toBe(true); | ||
expect(client_error.error_response).toStrictEqual(error_response); | ||
expect(client_error.name).toBe('ClientError'); | ||
}); | ||
it('should create a default client error if response does not have the structure of a client error payload', () => { | ||
const response = { | ||
code: 422, | ||
body: { foo: 'this is not the structure of a client error response' }, | ||
}; | ||
const client_error = client_error_1.createClientErrorForResponse(response); | ||
expect(client_error.client_http_status_code).toBe(422); | ||
expect(client_error.is_client_error).toBe(true); | ||
expect(client_error.error_response).toStrictEqual({ error: { code: 'client-error', message: 'Client error' } }); | ||
expect(client_error.name).toBe('ClientError'); | ||
}); | ||
}); |
@@ -19,2 +19,3 @@ export declare type ClientHttpStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 422 | 425 | 426 | 428 | 429 | 431 | 451; | ||
export declare function createClientError(params: CreateClientErrorParams): ClientError; | ||
export declare function createClientErrorForResponse(response: any): ClientError; | ||
//# sourceMappingURL=client-error.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createClientError = void 0; | ||
exports.createClientErrorForResponse = exports.createClientError = void 0; | ||
class ClientErrorImpl extends Error { | ||
@@ -23,1 +23,13 @@ constructor(params) { | ||
exports.createClientError = createClientError; | ||
// Returns a default client error or uses data in the response if it has the structure of a client error | ||
function createClientErrorForResponse(response) { | ||
var _a; | ||
let code = 'client-error'; | ||
let message = 'Client error'; | ||
if ((_a = response.body) === null || _a === void 0 ? void 0 : _a.error) { | ||
code = response.body.error.code; | ||
message = response.body.error.message; | ||
} | ||
return createClientError({ code, message, client_http_status_code: response.code }); | ||
} | ||
exports.createClientErrorForResponse = createClientErrorForResponse; |
@@ -6,2 +6,13 @@ # Change Log | ||
# [3005.34.0](https://github.com/Springworks/m2h-mono/compare/v3005.33.0...v3005.34.0) (2021-03-04) | ||
### Features | ||
* **error-factory:** add createClientErrorForResponse ([6c24067](https://github.com/Springworks/m2h-mono/commit/6c24067ba370130c290857fbb9a19d7268fd42e2)) | ||
# [3005.23.0](https://github.com/Springworks/m2h-mono/compare/v3005.22.3...v3005.23.0) (2021-02-11) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@springworks/error-factory", | ||
"version": "3005.23.0", | ||
"version": "3005.34.0", | ||
"description": "Custom error that makes use of HTTP error codes to identify different error types.", | ||
@@ -32,3 +32,3 @@ "main": "build/main.js", | ||
"homepage": "https://github.com/Springworks/m2h-mono/tree/master/packages/error-factory#readme", | ||
"gitHead": "6a4826f9e130e52b3dd0b6386e7529e1489804e2" | ||
"gitHead": "01144163344c18e89522a38d0825d9ec36e33a70" | ||
} |
Sorry, the diff of this file is not supported yet
43897
513