mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: Linter rule for properly formatted api errors (#2123)
* chore: Linter rule for properly formatted api errors * Add omitempty to 'Detail' field
This commit is contained in:
@ -63,7 +63,7 @@ type Response struct {
|
||||
// err.Error() text.
|
||||
// - "database: too many open connections"
|
||||
// - "stat: too many open files"
|
||||
Detail string `json:"detail"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
// Validations are form field-specific friendly error messages. They will be
|
||||
// shown on a form field in the UI. These can also be used to add additional
|
||||
// context if there is a set of errors in the primary 'Message'.
|
||||
@ -78,7 +78,7 @@ type Error struct {
|
||||
|
||||
func Forbidden(rw http.ResponseWriter) {
|
||||
Write(rw, http.StatusForbidden, Response{
|
||||
Message: "Forbidden",
|
||||
Message: "Forbidden.",
|
||||
})
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ func Read(rw http.ResponseWriter, r *http.Request, value interface{}) bool {
|
||||
err := json.NewDecoder(r.Body).Decode(value)
|
||||
if err != nil {
|
||||
Write(rw, http.StatusBadRequest, Response{
|
||||
Message: "Request body must be valid JSON",
|
||||
Message: "Request body must be valid JSON.",
|
||||
Detail: err.Error(),
|
||||
})
|
||||
return false
|
||||
@ -123,14 +123,14 @@ func Read(rw http.ResponseWriter, r *http.Request, value interface{}) bool {
|
||||
})
|
||||
}
|
||||
Write(rw, http.StatusBadRequest, Response{
|
||||
Message: "Validation failed",
|
||||
Message: "Validation failed.",
|
||||
Validations: apiErrors,
|
||||
})
|
||||
return false
|
||||
}
|
||||
if err != nil {
|
||||
Write(rw, http.StatusInternalServerError, Response{
|
||||
Message: "Internal error validating request body payload",
|
||||
Message: "Internal error validating request body payload.",
|
||||
Detail: err.Error(),
|
||||
})
|
||||
return false
|
||||
|
Reference in New Issue
Block a user