-
Notifications
You must be signed in to change notification settings - Fork 419
/
interceptor.ts
41 lines (34 loc) · 1.14 KB
/
interceptor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { retry } from "@trigger.dev/sdk/v3";
import { HttpResponse, delay, http } from "msw";
export const interceptor = retry.interceptFetch(
http.get("http://my.host/test-headers", ({ request }) => {
const retryCount = request.headers.get("x-retry-count");
if (retryCount === "1") {
return new HttpResponse(null, {
status: 429,
headers: {
"x-ratelimit-limit": "100",
"x-ratelimit-remaining": "0",
"x-ratelimit-reset": String(Date.now() + 1000 * 10), // 10 seconds
},
});
}
return HttpResponse.json({ test: "headers" });
}),
http.get("http://my.host/test-backoff", ({ request }) => {
const retryCount = request.headers.get("x-retry-count");
if (retryCount === "4") {
return HttpResponse.json({ test: "backoff" });
}
return new HttpResponse(null, {
status: 500,
});
}),
http.get("http://my.host/test-connection-errors", ({ request }) => {
const retryCount = request.headers.get("x-retry-count");
if (retryCount === "2") {
return HttpResponse.json({ test: "connection-errors" });
}
return HttpResponse.error();
})
);