axios-chaos-interceptor inject random errors into the response of axios.
🌪 Randomize axios response
⏱ Delay axios response
Use chaosInterceptor
const client = axios.create();
const chaosInterceptor = createChaosInterceptor();
client.interceptors.response.use(chaosInterceptor);
then
try {
await axios.get("http://api.github.com/");
} catch (error) {
// may happen AxiosError with random
console.log(error.status);
console.log(error.data);
}
Possible error.status
is one of following
- 429
- 500
- 502
- 503
- 504
Possible error.data
is one of following
- "Too Many Requests"
- "Internal Server Error"
- "Bad Gateway"
- "Service Unavailable"
- "Gateway Timeout"
Specify the response that will result in an error
const client = axios.create();
const chaosInterceptor = createChaosInterceptor([
{
status: 500,
body: {
message: "Internal Server Error",
},
delay: 500, // delay response (ms)
rate: 10, // possibilities (%)
},
{
status: 504,
body: {
message: "Gateway Timeout",
},
delay: 100000,
rate: 20,
},
]);
client.interceptors.response.use(chaosInterceptor);
Possible error.status
is one of following
- 500
- 504
Possible error.data
is one of following
{ message: "Internal Server Error" }
{ message: "Gateway Timeout" }