Skip to content

Instantly share code, notes, and snippets.

@pulkitkumar
Last active August 13, 2018 11:32
Show Gist options
  • Save pulkitkumar/5afc2ce431d99aba3a8acf0f29a0514d to your computer and use it in GitHub Desktop.
Save pulkitkumar/5afc2ce431d99aba3a8acf0f29a0514d to your computer and use it in GitHub Desktop.
Network Error
// 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