Skip to content

Instantly share code, notes, and snippets.

@pawelgagorowski
Last active January 22, 2021 08:05
Show Gist options
  • Save pawelgagorowski/3b5579ef4878724adddd0bdea2ab9f53 to your computer and use it in GitHub Desktop.
Save pawelgagorowski/3b5579ef4878724adddd0bdea2ab9f53 to your computer and use it in GitHub Desktop.
class CustomError extends Error {
static createCustomErrorResposne(statusCode: number, answer?: string): ErrorResponseType {
return {
statusCode: statusCode,
answer: answer = ''
}
}
static isErrorInstanceOfCustomError(error: any): boolean {
if(error instanceof CustomError) return true
else return false;
}
createCustomErrorMessage(errorMessage: string): CustomErrorMessageType {
return {
answer: errorMessage
}
}
}
#
class TestingLessonValidation {
static validateHeader(headers: UserHeaders, errorMessage: string): void {
if(!headers["X-userr"]) {
const error = new CustomError();
throw error.createCustomErrorMessage(errorMessage);
}
}
}
CustomError.isErrorInstanceOfCustomError(e) // -> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment