axios-chaos-interceptor
v1.0.2
Published
Inject chaos to axios. Randomize response.
Downloads
58
Maintainers
Readme
axios-chaos-interceptor
Features
🌪 Randomize axios response ⏱ Delay axios response
Usage
Basic Usage
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"
Params
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" }