ErrorWithHeaders wraps an error with additional headers to be sent to the client. This is useful for e.g. caching, rate limiting, or other metadata.
(err error, headers http.Header)
| 179 | // ErrorWithHeaders wraps an error with additional headers to be sent to the |
| 180 | // client. This is useful for e.g. caching, rate limiting, or other metadata. |
| 181 | func ErrorWithHeaders(err error, headers http.Header) error { |
| 182 | var he HeadersError |
| 183 | if errors.As(err, &he) { |
| 184 | // There is already a headers error, so we need to merge the headers. This |
| 185 | // lets you chain multiple calls together and have all the headers set. |
| 186 | orig := he.GetHeaders() |
| 187 | for k, values := range headers { |
| 188 | for _, v := range values { |
| 189 | orig.Add(k, v) |
| 190 | } |
| 191 | } |
| 192 | return err |
| 193 | } |
| 194 | return &errWithHeaders{err: err, headers: headers} |
| 195 | } |
| 196 | |
| 197 | // NewError creates a new instance of an error model with the given status code, |
| 198 | // message, and optional error details. If the error details implement the |
nothing calls this directly
no test coverage detected
searching dependent graphs…