-
-
Save dpjayasekara/9d77759ba5bfb1bed172ab1db00e98c5 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 UserServiceError extends Error { | |
constructor(...args) { | |
super(...args); | |
this.code = 'ERR_USER_SERVICE'; | |
this.name = 'UserServiceError'; | |
this.stack = `${this.message}\n${new Error().stack}`; | |
} | |
} | |
class InvalidInputError extends Error { | |
constructor(...args) { | |
super(...args); | |
this.code = 'ERR_INVALID_INPUT'; | |
this.name = 'InvalidInputError'; | |
this.stack = `${this.message}\n${new Error().stack}`; | |
} | |
} | |
async function getUser(userId) { | |
if (!userId) throw new InvalidInputError('userId is not provided'); | |
try { | |
return getUserFromApi(userId); | |
} catch (err) { | |
throw new UserServiceError(err.message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment