-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
72 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
export declare class CustomError extends Error { | ||
constructor( | ||
message: string, | ||
public readonly code: number, | ||
public readonly metadata: Record<string, unknown> | ||
) { | ||
super(message) | ||
this.name = 'CustomError' | ||
} | ||
} | ||
export declare class CustomErrorWithMethod extends CustomError { | ||
logError() { | ||
console.error(`[${this.code}] ${this.message}`) | ||
} | ||
} | ||
export declare class CustomErrorWithMethodAndType extends CustomError { | ||
logError(): void { | ||
console.error(`[${this.code}] ${this.message}`) | ||
} | ||
|
||
getError(): Error { | ||
return this | ||
} | ||
} | ||
export declare class CustomErrorWithMethodAndTypeAndReturn { | ||
constructor( | ||
private message: string, | ||
public readonly code: number, | ||
public readonly metadata: Record<string, unknown> | ||
) { | ||
this.message = message | ||
this.code = code | ||
this.metadata = metadata | ||
} | ||
|
||
logError(): void { | ||
console.error(`[${this.code}] ${this.message}`) | ||
} | ||
|
||
getError(): Error { | ||
return new Error(this.message) | ||
} | ||
} | ||
export declare class Result<T, E extends Error> { | ||
constructor( | ||
readonly value: T | null = null, | ||
readonly error: E | null = null | ||
) {} | ||
|
||
isOk(): this is { readonly value: T } { | ||
return this.value !== null && this.error === null; | ||
} | ||
|
||
isErr(): this is { readonly error: E } { | ||
return this.error !== null && this.value === null; | ||
} | ||
} |