Skip to content

Instantly share code, notes, and snippets.

@pulkitkumar
Created August 13, 2018 09:51
Show Gist options
  • Save pulkitkumar/7d562ac6a54d639189d938e45f40f093 to your computer and use it in GitHub Desktop.
Save pulkitkumar/7d562ac6a54d639189d938e45f40f093 to your computer and use it in GitHub Desktop.
Handling Network error
func networkRequest() {
body, err := makeRequest("url", "GET")
if err != nil {
switch err := err.(type) {
case *NetworkError:
if err.IsAccessDenied() {
// handle access denied here.
} else if err.IsAuthError() {
// handle auth error here.
} else if err.IsResourceNotFound() {
// handle resource not found here.
} else if err.IsServerError() {
// handle server error here.
}
break
case *InvalidUrlError:
// handle invalid url error.
break
default:
// handle other errors
}
}
// handle body
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment