Skip to content

Commit 835e29e

Browse files
committed
feat: add HTTPStatusError custom throw error
1 parent 65baf29 commit 835e29e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/utils/http-status-error.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class HTTPStatusError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this.name = 'HTTPStatusError';
5+
}
6+
}
7+
8+
export default HTTPStatusError;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import HTTPStatusError from './http-status-error';
2+
13
function validateHttpStatus(status, expectedStatus) {
24
try {
35
const isValid = status === expectedStatus;
46

57
if (!isValid) {
6-
throw new Error(`Expected a ${expectedStatus} response.`);
8+
throw new HTTPStatusError(`Expected a ${expectedStatus} response.`);
79
}
810
return isValid;
911
} catch (e) {

0 commit comments

Comments
 (0)