Skip to content

Commit 2e6e186

Browse files
committed
fix: uses AxiosError on rejected responses
1 parent 31d9c94 commit 2e6e186

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/runtime/docGenerator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
interface MockResponse {
22
status: number;
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34
body: any;
45
}
56

@@ -15,6 +16,7 @@ interface OpenAPI {
1516
title: string;
1617
version: string;
1718
};
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1820
paths: Record<string, any>;
1921
}
2022

@@ -38,6 +40,7 @@ export class DocGenerator {
3840
method: string,
3941
path: string,
4042
status: number,
43+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4144
body: any,
4245
): void {
4346
// Verifica se já existe um mock com o mesmo método e path para evitar duplicação

src/runtime/handler.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AxiosResponse } from 'axios';
2+
import { AxiosError } from 'axios';
23
import type {
34
RequestConfigChanger,
45
ResponseChanger,
@@ -62,7 +63,16 @@ export default class Handler {
6263
request: requestConfig,
6364
};
6465
if (status < 400) resolve(response);
65-
else reject(response);
66+
else {
67+
const err = new AxiosError(
68+
`Request failed with status code ${status}`,
69+
status >= 500 ? 'ERR_BAD_RESPONSE' : 'ERR_BAD_REQUEST',
70+
config,
71+
response.request,
72+
response,
73+
);
74+
reject(err);
75+
}
6676
},
6777
);
6878
return;
@@ -77,7 +87,16 @@ export default class Handler {
7787
request: requestConfig,
7888
};
7989
if (status < 400) resolve(response);
80-
else reject(response);
90+
else {
91+
const err = new AxiosError(
92+
`Request failed with status code ${status}`,
93+
status >= 500 ? 'ERR_BAD_RESPONSE' : 'ERR_BAD_REQUEST',
94+
config,
95+
response.request,
96+
response,
97+
);
98+
reject(err);
99+
}
81100
});
82101
};
83102
}

0 commit comments

Comments
 (0)