mirror of
https://github.com/distribution/distribution.git
synced 2025-09-12 13:23:32 +00:00
fix: if reference exceeds the threshold return 400 and detail
If the reference in the API request exceeds the threshold allowed by the reference package (NOTE: this isn't defined by distribution specification!) we return 500 back to the client. This commit makes sure we return 400 and the explanation of the error in the returned JSON payload. Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
This commit is contained in:
@@ -224,11 +224,20 @@ func (errs Errors) MarshalJSON() ([]byte, error) {
|
||||
msg = err.Code.Message()
|
||||
}
|
||||
|
||||
tmpErrs.Errors = append(tmpErrs.Errors, Error{
|
||||
tmpErr := Error{
|
||||
Code: err.Code,
|
||||
Message: msg,
|
||||
Detail: err.Detail,
|
||||
})
|
||||
}
|
||||
|
||||
// if the detail contains error extract the error message
|
||||
// otherwise json.Marshal will not serialize it at all
|
||||
// https://github.com/golang/go/issues/10748
|
||||
if detail, ok := tmpErr.Detail.(error); ok {
|
||||
tmpErr.Detail = detail.Error()
|
||||
}
|
||||
|
||||
tmpErrs.Errors = append(tmpErrs.Errors, tmpErr)
|
||||
}
|
||||
|
||||
return json.Marshal(tmpErrs)
|
||||
|
Reference in New Issue
Block a user