Export ServeJSON for serving error codes
This changeset provides a common http handler for serving errcodes. This should unify http responses across webservices in the face of errors. Several type assertions have been added, as well, to ensure the error interface is implemented. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
c958371f4b
commit
81c21411e8
4 changed files with 65 additions and 44 deletions
|
@ -16,6 +16,8 @@ type ErrorCoder interface {
|
|||
// and the integer format may change and should *never* be exported.
|
||||
type ErrorCode int
|
||||
|
||||
var _ error = ErrorCode(0)
|
||||
|
||||
// ErrorCode just returns itself
|
||||
func (ec ErrorCode) ErrorCode() ErrorCode {
|
||||
return ec
|
||||
|
@ -93,6 +95,8 @@ type Error struct {
|
|||
// variable substitution right before showing the message to the user
|
||||
}
|
||||
|
||||
var _ error = Error{}
|
||||
|
||||
// ErrorCode returns the ID/Value of this Error
|
||||
func (e Error) ErrorCode() ErrorCode {
|
||||
return e.Code
|
||||
|
@ -163,6 +167,8 @@ func ParseErrorCode(value string) ErrorCode {
|
|||
// for use within the application.
|
||||
type Errors []error
|
||||
|
||||
var _ error = Errors{}
|
||||
|
||||
func (errs Errors) Error() string {
|
||||
switch len(errs) {
|
||||
case 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue