Skip to content

Commit ee95c49

Browse files
author
Ruben van Leeuwen
committed
2143: Reject if not valid return code
1 parent fee729d commit ee95c49

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

frontend/apps/example/src/app/page.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,24 @@ export default function Home() {
4242
fetchResult.status === 201
4343
) {
4444
const data = await fetchResult.json();
45-
return new Promise<Record<string, unknown>>((resolve) => {
46-
if (fetchResult.status === 510 || fetchResult.status === 400) {
47-
resolve({ ...data, status: fetchResult.status });
48-
}
49-
if (fetchResult.status === 200) {
50-
resolve({ status: 200, data });
51-
}
52-
});
45+
46+
return new Promise<Record<string, unknown>>(
47+
(resolve, reject) => {
48+
if (
49+
fetchResult.status === 510 ||
50+
fetchResult.status === 400
51+
) {
52+
resolve({
53+
...data,
54+
status: fetchResult.status,
55+
});
56+
}
57+
if (fetchResult.status === 200) {
58+
resolve({ status: 200, data });
59+
}
60+
reject('No valid status in response');
61+
},
62+
);
5363
}
5464
throw new Error(
5565
`Status not 400, 510 or 200: ${fetchResult.statusText}`,

0 commit comments

Comments
 (0)