Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Last active May 18, 2020 00:50
Show Gist options
  • Save zzdjk6/28da18dfaffc9e5857cffd65f9becd36 to your computer and use it in GitHub Desktop.
Save zzdjk6/28da18dfaffc9e5857cffd65f9becd36 to your computer and use it in GitHub Desktop.
More Readable #EarlyReturn
function doSomething(user, data) {
if (!hasPermission(user)) {
throw new PermissionDeniedError();
}
if (!isNetworkAvailable()) {
saveInQueue(user, data);
return;
}
if (!isValid(data)) {
throw new DataInvalidError();
}
sendToServer(user, data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment