In situations where the containerd error is consumed directly
and not received over gRPC, errors were not translated.
This patch converts containerd errors to the correct HTTP
status code.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The `ErrAlreadyExists` error is used for 304 statuses, which
is not an error-condition, so should probably not be defined
as part of the errdefs package.
This patch removes the `ErrAlreadyExists` interface, and related
helpers, as it was currently not used.
Note that a 304 status can fulfil certain use-cases, but (refering
to https://www.codetinkerer.com/2015/12/04/choosing-an-http-status-code.html)
could probably be handled by a 200 OK, unless we want to perform
caching in the client.
If we do want to use 304 statuses, perhaps we need a separate class
of "errors" for this (?).
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The types defined in the errdefs package do not
satisfy the `error` interface, because they do not
implement `Error()`.
Instead of returning the matched interface, return
the original error.
When matching _multiple_ interfaces/types, Golang doesn't complain:
func getImplementer(err error) error {
switch e := err.(type) {
case
ErrNotFound,
ErrInvalidParameter:
return e
default:
return err
}
}
But matching a single interface/type:
func getImplementer(err error) error {
switch e := err.(type) {
case
ErrNotFound:
return e
default:
return err
}
}
Produces an error:
cannot use e (type ErrNotFound) as type error in return argument: ErrNotFound does not implement error (missing Error method)
Return the original `err` instead of the matched interface/type instead.
Also added some additional tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>