Skip to content

Commit cc4e08f

Browse files
committed
feat(common): introduce NfFetchException for improved fetch error handling
1 parent c9ba618 commit cc4e08f

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/common/src/common/file.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { NfFetchException } from "../exception/exceptions/fetch.exception";
2+
13
export class NfFile {
24
private readonly _path: string;
35

@@ -41,7 +43,7 @@ export class NfFile {
4143

4244
private async _fetch(): Promise<Response> {
4345
const res = await fetch(this._path);
44-
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
46+
if (!res.ok) throw new NfFetchException(res.status, res.statusText);
4547
return res;
4648
}
4749
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NfException } from "../abstracts/exception.abstract";
2+
3+
export class NfFetchException extends NfException {
4+
private readonly _code: number;
5+
6+
get code(): number {
7+
return this._code;
8+
}
9+
10+
constructor(code: number, text: string) {
11+
super(`Fetch exception : ${code} - ${text}`);
12+
this._code = code;
13+
}
14+
}

0 commit comments

Comments
 (0)