Errors

11-04-2019
To throw an internal error just use a string: ```` throw "Resource type required" ``` Wrap it if you want to provide more context: ``` throw errors.wrap("Error connecting to the database", error) ``` In release mode users will see the message "Internal error" regardless of the provided message. In debug mode you will see all the error information including the full stack trace. Users should see more information than just "Internal error". To show something helpful: ``` throw errors.show("Resource type required") ``` If you add an error object it will be logged and notified to the system admin but not shown to the user: ``` throw errors.show("Resource type required", error) ``` To prevent notifying the system admin, for example for a basic validation error: ``` throw errors.show("Resource type required", error, true) ``` The errors namespace: ``` declare namespace errors { export function wrap(msg: string, inner: Error): Error export function show(msg: string, inner?: Error | string, skipNotify?: boolean): Error export interface Error { type: string public: boolean message: string pc: number skipNotify: boolean stackTrace: string toString(): string } } ```