...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package registry
16
17 import (
18 "encoding/json"
19 "net/http"
20 )
21
22 type regError struct {
23 Status int
24 Code string
25 Message string
26 }
27
28 func (r *regError) Write(resp http.ResponseWriter) error {
29 resp.WriteHeader(r.Status)
30
31 type err struct {
32 Code string `json:"code"`
33 Message string `json:"message"`
34 }
35 type wrap struct {
36 Errors []err `json:"errors"`
37 }
38 return json.NewEncoder(resp).Encode(wrap{
39 Errors: []err{
40 {
41 Code: r.Code,
42 Message: r.Message,
43 },
44 },
45 })
46 }
47
48
49 func regErrInternal(err error) *regError {
50 return ®Error{
51 Status: http.StatusInternalServerError,
52 Code: "INTERNAL_SERVER_ERROR",
53 Message: err.Error(),
54 }
55 }
56
57 var regErrBlobUnknown = ®Error{
58 Status: http.StatusNotFound,
59 Code: "BLOB_UNKNOWN",
60 Message: "Unknown blob",
61 }
62
63 var regErrUnsupported = ®Error{
64 Status: http.StatusMethodNotAllowed,
65 Code: "UNSUPPORTED",
66 Message: "Unsupported operation",
67 }
68
69 var regErrDigestMismatch = ®Error{
70 Status: http.StatusBadRequest,
71 Code: "DIGEST_INVALID",
72 Message: "digest does not match contents",
73 }
74
75 var regErrDigestInvalid = ®Error{
76 Status: http.StatusBadRequest,
77 Code: "NAME_INVALID",
78 Message: "invalid digest",
79 }
80
View as plain text