diff --git a/packages/plantae/src/axios/createAxiosInterceptors.spec.ts b/packages/plantae/src/axios/createAxiosInterceptors.spec.ts index 8bc8706..73dc5c6 100644 --- a/packages/plantae/src/axios/createAxiosInterceptors.spec.ts +++ b/packages/plantae/src/axios/createAxiosInterceptors.spec.ts @@ -584,4 +584,29 @@ describe("createAxiosInterceptors", () => { "Request failed with status code 500", ); }); + + it("should throw error if status code validation failed", async () => { + server.use( + http.get(base("/"), () => { + return new Response(null, { + status: 500, + }); + }), + ); + + const axios = Axios.create({ + baseURL, + }); + + const { request, response } = createAxiosInterceptors({ + plugins: [], + }); + + axios.interceptors.request.use(request.onFulfilled, request.onRejected); + axios.interceptors.response.use(response.onFulfilled, response.onRejected); + + await expect(axios.get("/")).rejects.toThrow( + "Request failed with status code 500", + ); + }); }); diff --git a/packages/plantae/src/axios/createAxiosInterceptors.ts b/packages/plantae/src/axios/createAxiosInterceptors.ts index de89749..5bba55f 100644 --- a/packages/plantae/src/axios/createAxiosInterceptors.ts +++ b/packages/plantae/src/axios/createAxiosInterceptors.ts @@ -5,6 +5,8 @@ import type { InternalAxiosRequestConfig, } from "axios"; +import Axios from "axios"; + import createMiddleware from "../createMiddleware"; import type { AdapterRequest, AdapterResponse, Plugin } from "../types"; import { isArrayBuffer, isNullBodyStatus } from "../utils"; @@ -191,10 +193,10 @@ async function extendClientResponse( } const createAxiosInterceptors = ({ - client, + client = Axios.create(), plugins, }: { - client: AxiosInstance; + client?: AxiosInstance; plugins?: Plugin[]; }): { request: Interceptor<"request">;