errors.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package registry
  2. import (
  3. "net/url"
  4. "github.com/docker/distribution/registry/api/errcode"
  5. )
  6. type notFoundError string
  7. func (e notFoundError) Error() string {
  8. return string(e)
  9. }
  10. func (notFoundError) NotFound() {}
  11. type validationError struct {
  12. cause error
  13. }
  14. func (e validationError) Error() string {
  15. return e.cause.Error()
  16. }
  17. func (e validationError) InvalidParameter() {}
  18. func (e validationError) Cause() error {
  19. return e.cause
  20. }
  21. type unauthorizedError struct {
  22. cause error
  23. }
  24. func (e unauthorizedError) Error() string {
  25. return e.cause.Error()
  26. }
  27. func (e unauthorizedError) Unauthorized() {}
  28. func (e unauthorizedError) Cause() error {
  29. return e.cause
  30. }
  31. type systemError struct {
  32. cause error
  33. }
  34. func (e systemError) Error() string {
  35. return e.cause.Error()
  36. }
  37. func (e systemError) SystemError() {}
  38. func (e systemError) Cause() error {
  39. return e.cause
  40. }
  41. type notActivatedError struct {
  42. cause error
  43. }
  44. func (e notActivatedError) Error() string {
  45. return e.cause.Error()
  46. }
  47. func (e notActivatedError) Forbidden() {}
  48. func (e notActivatedError) Cause() error {
  49. return e.cause
  50. }
  51. func translateV2AuthError(err error) error {
  52. switch e := err.(type) {
  53. case *url.Error:
  54. switch e2 := e.Err.(type) {
  55. case errcode.Error:
  56. switch e2.Code {
  57. case errcode.ErrorCodeUnauthorized:
  58. return unauthorizedError{err}
  59. }
  60. }
  61. }
  62. return err
  63. }