Better expected errors handling

This commit is contained in:
DarthSim
2018-11-20 18:53:44 +06:00
parent 4187646052
commit 6997e585ef
5 changed files with 41 additions and 32 deletions

View File

@@ -13,17 +13,17 @@ type imgproxyError struct {
PublicMessage string
}
func (e imgproxyError) Error() string {
func (e *imgproxyError) Error() string {
return e.Message
}
func newError(status int, msg string, pub string) imgproxyError {
return imgproxyError{status, msg, pub}
func newError(status int, msg string, pub string) *imgproxyError {
return &imgproxyError{status, msg, pub}
}
func newUnexpectedError(err error, skip int) imgproxyError {
func newUnexpectedError(err error, skip int) *imgproxyError {
msg := fmt.Sprintf("Unexpected error: %s\n%s", err, stacktrace(skip+1))
return imgproxyError{500, msg, "Internal error"}
return &imgproxyError{500, msg, "Internal error"}
}
func stacktrace(skip int) string {