Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.