mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Fixed tets cases
This commit is contained in:
parent
280e96f38a
commit
bfbb6d2a74
@ -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}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -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}\`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user