-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,27 @@ | ||
import { ErrorBase } from './errors'; | ||
|
||
interface NetworkError { | ||
kind: 'network'; | ||
issue: 'unsigned-ssl' | 'dns' | 'timeout' | 'reject'; | ||
} | ||
|
||
interface RequestError { | ||
kind: 'request'; | ||
issue: 'abort' | 'timeout'; | ||
} | ||
type NetworkErrorIssue = 'unsigned-ssl' | 'dns' | 'timeout' | 'reject'; | ||
type RequestErrorIssue = 'abort' | 'timeout'; | ||
type FetchErrorIssue = NetworkErrorIssue | RequestErrorIssue; | ||
|
||
export type FetchErrorIssue = NetworkError['issue'] | RequestError['issue']; | ||
|
||
export class FetchErrorBase extends ErrorBase { | ||
export abstract class FetchError extends ErrorBase { | ||
constructor(kind: string, public issue: FetchErrorIssue) { | ||
super(kind, `Fetch failed: ${issue} issue`); | ||
} | ||
} | ||
|
||
export class NetworkFetchError extends FetchErrorBase { | ||
constructor(public override issue: NetworkError['issue']) { | ||
super('NetworkError', issue); | ||
} | ||
|
||
public get normalized(): NetworkError { | ||
return { kind: 'network', issue: this.issue }; | ||
export class NetworkFetchError extends FetchError { | ||
constructor(public override issue: NetworkErrorIssue) { | ||
super(NetworkFetchError.name, issue); | ||
} | ||
} | ||
|
||
export class RequestFetchError extends FetchErrorBase { | ||
constructor(public override issue: RequestError['issue']) { | ||
super('RequestError', issue); | ||
} | ||
|
||
public get normalized(): RequestError { | ||
return { kind: 'request', issue: this.issue }; | ||
export class RequestFetchError extends FetchError { | ||
constructor(public override issue: RequestErrorIssue) { | ||
super(RequestFetchError.name, issue); | ||
} | ||
} | ||
|
||
export type FetchError = NetworkFetchError | RequestFetchError; | ||
|
||
export function isFetchError(input: unknown): input is FetchError { | ||
return ( | ||
typeof input === 'object' && | ||
(input instanceof NetworkFetchError || input instanceof RequestFetchError) | ||
); | ||
return input instanceof FetchError; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,33 @@ | ||
import { ErrorBase } from './errors'; | ||
|
||
export class FileExistsError extends ErrorBase { | ||
export abstract class FileSystemError extends ErrorBase {} | ||
|
||
export class FileExistsError extends FileSystemError { | ||
constructor(message: string) { | ||
super(FileExistsError.name, message); | ||
} | ||
} | ||
|
||
export class PermissionDeniedError extends ErrorBase { | ||
export class PermissionDeniedError extends FileSystemError { | ||
constructor(message: string) { | ||
super(PermissionDeniedError.name, message); | ||
} | ||
} | ||
|
||
export class NotEmptyError extends ErrorBase { | ||
export class NotEmptyError extends FileSystemError { | ||
constructor(message: string) { | ||
super(NotEmptyError.name, message); | ||
} | ||
} | ||
|
||
export class NotFoundError extends ErrorBase { | ||
export class NotFoundError extends FileSystemError { | ||
constructor(message: string) { | ||
super(NotFoundError.name, message); | ||
} | ||
} | ||
|
||
export class UnknownFileSystemError extends ErrorBase { | ||
export class UnknownFileSystemError extends FileSystemError { | ||
constructor(message: string) { | ||
super(UnknownFileSystemError.name, message); | ||
} | ||
} | ||
|
||
// TODO: Turn to class FileSystemError | ||
export type FileSystemError = | ||
| FileExistsError | ||
| PermissionDeniedError | ||
| NotEmptyError | ||
| NotFoundError | ||
| UnknownFileSystemError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters