Import other modules into monorepo
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
26
src/util/error/ErrorWithContext.ts
Normal file
26
src/util/error/ErrorWithContext.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* An Error base-class that also provides some additional context.
|
||||
*
|
||||
* All first-party error handlers in Extollo can render the context as part of
|
||||
* the display of the error (e.g. in the console, in the HTML response, &c.)
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* function myFunc(arg1, arg2) {
|
||||
* // ...do something...
|
||||
* throw new ErrorWithContext('Something went wrong!', { arg1, arg2 })
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export class ErrorWithContext extends Error {
|
||||
public context: {[key: string]: any} = {}
|
||||
public originalError?: Error
|
||||
|
||||
constructor(
|
||||
message: string,
|
||||
context?: {[key: string]: any}
|
||||
) {
|
||||
super(message)
|
||||
if ( context ) this.context = context
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user