Last active
January 22, 2021 08:05
-
-
Save pawelgagorowski/3b5579ef4878724adddd0bdea2ab9f53 to your computer and use it in GitHub Desktop.
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
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