Last active
August 13, 2018 11:32
-
-
Save pulkitkumar/5afc2ce431d99aba3a8acf0f29a0514d to your computer and use it in GitHub Desktop.
Network Error
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
// Network error, when the status code from a network request is > 400 | |
type NetworkError struct { | |
statusCode int | |
Body string | |
} | |
func (n *NetworkError) IsAuthError() bool { | |
return n.statusCode == 401 | |
} | |
func (n *NetworkError) IsResourceNotFound() bool { | |
return n.statusCode == 404 | |
} | |
func (n *NetworkError) IsServerError() bool { | |
return n.statusCode >= 500 | |
} | |
func (n *NetworkError) IsAccessDenied() bool { | |
return n.statusCode == 403 | |
} | |
func (n *NetworkError) Error() string { | |
return fmt.Sprintf("Network error with status code: %d", n.statusCode) | |
} | |
// InvalidUrlError , this error occurs when the url passed for the network request is invalid. ex: (does not contain protocol etc.) | |
type InvalidUrlError struct { | |
url string | |
} | |
func (e *InvalidUrlError) Error() string { | |
return fmt.Sprintf("The URL %s is not a valid url", e.url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment