Created
December 31, 2017 20:21
-
-
Save didenko/9f9eed12fca838c02736d2971b3b7d6a to your computer and use it in GitHub Desktop.
http_error.go
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
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/pkg/errors" | |
) | |
type HTTPError struct { | |
error | |
status int | |
url string | |
} | |
func NewHTTPError(status int, url string) *HTTPError { | |
return &HTTPError{errors.New("http error"), status, url} | |
} | |
func (e *HTTPError) Error() string { | |
return fmt.Sprintf("%s: status %d from %q", e.Error(), e.status, e.url) | |
} | |
func (e *HTTPError) Status() int { | |
return e.status | |
} | |
func (e *HTTPError) URL() (int, string) { | |
return 0, e.url | |
} | |
func main() { | |
he := NewHTTPError(404, "http://example.com:3000/fail") | |
log.Println("----------") | |
log.Println(he) | |
log.Println("----------") | |
log.Print(he) | |
log.Println("----------") | |
log.Println(he.URL()) | |
log.Println("----------") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment