Fixed tets cases

This commit is contained in:
Ferdi Koomen 2023-04-11 09:59:38 +02:00
parent 280e96f38a
commit bfbb6d2a74
14 changed files with 54 additions and 25 deletions

View File

@ -1,3 +1,5 @@
export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
const errors: Record<number, string> = {
400: 'Bad Request',
@ -16,16 +18,18 @@ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult):
}
if (!result.ok) {
const resultBody = (() => {
try {
return JSON.stringify(result.body, null, 2);
} catch (err) {
return undefined;
}
})();
throw new ApiError(
result,
`Generic Error: status: ${result.status ?? 'unknown'}; status text: ${result.statusText}; body: ${resultBody}`
);
const errorStatus = result.status ?? 'unknown';
const errorStatusText = result.statusText ?? 'unknown';
const errorBody = (() => {
try {
return JSON.stringify(result.body, null, 2);
} catch (e) {
return undefined;
}
})();
throw new ApiError(options, result,
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
);
}
};

View File

@ -498,7 +498,19 @@ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult):
}
if (!result.ok) {
throw new ApiError(options, result, 'Generic Error');
const errorStatus = result.status ?? 'unknown';
const errorStatusText = result.statusText ?? 'unknown';
const errorBody = (() => {
try {
return JSON.stringify(result.body, null, 2);
} catch (e) {
return undefined;
}
})();
throw new ApiError(options, result,
\`Generic Error: status: \${errorStatus}; status text: \${errorStatusText}; body: \${errorBody}\`
);
}
};
@ -3593,7 +3605,19 @@ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult):
}
if (!result.ok) {
throw new ApiError(options, result, 'Generic Error');
const errorStatus = result.status ?? 'unknown';
const errorStatusText = result.statusText ?? 'unknown';
const errorBody = (() => {
try {
return JSON.stringify(result.body, null, 2);
} catch (e) {
return undefined;
}
})();
throw new ApiError(options, result,
\`Generic Error: status: \${errorStatus}; status text: \${errorStatusText}; body: \${errorBody}\`
);
}
};

View File

@ -139,10 +139,11 @@ describe('client.angular', () => {
});
});
});
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -136,7 +136,7 @@ describe('client.axios', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -161,7 +161,7 @@ describe('client.babel', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -156,7 +156,7 @@ describe('client.fetch', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -136,7 +136,7 @@ describe('client.node', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -155,7 +155,7 @@ describe('client.xhr', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -144,7 +144,7 @@ describe('v3.angular', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -127,7 +127,7 @@ describe('v3.axios', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -153,7 +153,7 @@ describe('v3.babel', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -147,7 +147,7 @@ describe('v3.fetch', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -127,7 +127,7 @@ describe('v3.node', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',

View File

@ -146,7 +146,7 @@ describe('v3.xhr', () => {
expect(error).toBe(
JSON.stringify({
name: 'ApiError',
message: 'Generic Error',
message: 'Generic Error: status: 409; status text: Conflict; body: {\n "status": 409,\n "message": "hello world"\n}',
url: 'http://localhost:3000/base/api/v1.0/error?status=409',
status: 409,
statusText: 'Conflict',