Last active
June 5, 2021 04:43
-
-
Save mosufy/ee0d0d292e0385235ed099038596140d 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
const user = { | |
username: 'JohnDoe', | |
gender: 'male', | |
} | |
try { | |
validateUsernameFormat(user.username); | |
await checkUsernameExists(user.username); | |
} catch (error) { | |
return { | |
// a better approach is to have a response success/error function | |
error: { | |
message: error.message, | |
code: 'FAILED_USERNAME_VALIDATION', | |
} | |
} | |
} | |
try { | |
await insertNewUser(user); | |
} catch (error) { | |
return { | |
error: { | |
message: error.message, | |
code: 'FAILED_INSERT_USER', | |
} | |
} | |
} | |
try { | |
await sendMessage('User created', { userId, user }); | |
} catch (error) { | |
console.log('Failed to send message, but it is ok', error); | |
} | |
return { | |
data: { | |
message: 'User created successfully!' | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment