Friendly errors#16
Conversation
dhiltgen
left a comment
There was a problem hiding this comment.
It feels like clients might still wind up parsing error strings to see what happened...
| } | ||
| type LicensingError struct { | ||
| Msg string | ||
| Cause error |
There was a problem hiding this comment.
Might be helpful to put some comments on this to explain what Msg and Cause are as well as how this LicensingError should be used by clients of the library.
| func (l *LicensingError) Error() string { | ||
| // make an attempt to recover more detail for more specificity otherwise fallback on msg | ||
| if detail, ok := errors.HTTPDetail(l.Cause); ok && detail != "" { | ||
| return fmt.Sprintf("%s: %s", l.Msg, detail) |
There was a problem hiding this comment.
Could you give some examples of how this might look?
I'm still trying to wrap my head around how clients of the lib will use this, and if there might be a simpler model here perhaps.
| return err, false | ||
| } | ||
|
|
||
| func (l *LicensingError) GetCause() error { |
There was a problem hiding this comment.
Might want to consider implementing the Causer interface (which is what pkg/errors implement); https://github.com/pkg/errors/blob/master/errors.go#L32-L39
| @@ -22,6 +24,35 @@ func HTTPStatus(err error) (status int, ok bool) { | |||
| return http.StatusInternalServerError, false | |||
There was a problem hiding this comment.
FWIW; this is what's implemented by the engine; moby/moby#38689
Basically, it defines a few interfaces that can be taped to HTTP statuses (and vice-versa); https://github.com/moby/moby/blob/d48392a35b157612d28c48eb8e4fad1272fa1442/errdefs/defs.go#L35-L39
Adds a generic
LicensingErrorto facilitate friendlier error message returns, while also exposing a helper funcGetErrorCause()to retrieve the more verbose original. The simpler error return also digs into the underlying cause to attempt to retrieve a "detail" message.