WriteErr writes an error response with the given context, using the configured error type and with the given status code and message. It is marshaled using the API's content negotiation methods.
(api API, ctx Context, status int, msg string, errs ...error)
| 256 | // configured error type and with the given status code and message. It is |
| 257 | // marshaled using the API's content negotiation methods. |
| 258 | func WriteErr(api API, ctx Context, status int, msg string, errs ...error) error { |
| 259 | var err = NewErrorWithContext(ctx, status, msg, errs...) |
| 260 | |
| 261 | // NewError may have modified the status code, so update it here if needed. |
| 262 | // If it was not modified, then this is a no-op. |
| 263 | status = err.GetStatus() |
| 264 | |
| 265 | writtenErr := writeResponse(api, ctx, status, "", err) |
| 266 | if writtenErr != nil { |
| 267 | // If we can't write the error, log it so we know what happened. |
| 268 | fmt.Fprintf(os.Stderr, "could not write error: %v\n", writtenErr) |
| 269 | } |
| 270 | |
| 271 | return writtenErr |
| 272 | } |
| 273 | |
| 274 | // Status304NotModified returns a 304. This is not really an error, but |
| 275 | // provides a way to send non-default responses. |
no test coverage detected
searching dependent graphs…