Last active
December 31, 2017 20:36
-
-
Save didenko/51047a90e2f7b05e775b53e492299805 to your computer and use it in GitHub Desktop.
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.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