Created
August 13, 2018 09:51
-
-
Save pulkitkumar/7d562ac6a54d639189d938e45f40f093 to your computer and use it in GitHub Desktop.
Handling Network error
This file contains hidden or 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
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