Skip to content

Instantly share code, notes, and snippets.

@cn0047
Last active January 30, 2019 23:22
Show Gist options
  • Select an option

  • Save cn0047/3e7114de49aed9758df96f1b423c1957 to your computer and use it in GitHub Desktop.

Select an option

Save cn0047/3e7114de49aed9758df96f1b423c1957 to your computer and use it in GitHub Desktop.
DRY in GO - error handling
if err != nil {
httpErrorCode := 500
switch err {
case ErrorInvalidID:
httpErrorCode = 400
case ErrorUnauthorized:
httpErrorCode = 401
case ErrorEmployeeNotFound:
httpErrorCode = 404
// other errors
// ...
}
return "", httpErrorCode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment