-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Registry Endpoint Client Side Error (#65)
Co-authored-by: James Kwon <[email protected]>
- Loading branch information
1 parent
be76018
commit e4671e2
Showing
5 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package mapper | ||
|
||
import "errors" | ||
|
||
type errCode uint8 | ||
|
||
const ( | ||
errCodeUnknown errCode = iota | ||
errCodeBadRequest | ||
) | ||
|
||
type codedError struct { | ||
code errCode | ||
msg string | ||
err []error | ||
} | ||
|
||
func (e codedError) Error() string { | ||
return e.msg | ||
} | ||
|
||
func (e codedError) Unwrap() []error { | ||
return e.err | ||
} | ||
|
||
func isCodedError(err error, code errCode) bool { | ||
var e codedError | ||
if !errors.As(err, &e) { | ||
return false | ||
} | ||
|
||
return e.code == code | ||
} | ||
|
||
func NewErrorBadRequest(msg string, err ...error) error { | ||
return codedError{code: errCodeBadRequest, msg: msg, err: err} | ||
} | ||
|
||
func IsErrorBadRequest(err error) (y bool) { | ||
return isCodedError(err, errCodeBadRequest) | ||
} |
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
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
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