handleJSONError logs the error and responds with the given status code with a generic status text
(w http.ResponseWriter, err error, msg string)
| 250 | |
| 251 | // handleJSONError logs the error and responds with the given status code with a generic status text |
| 252 | func handleJSONError(w http.ResponseWriter, err error, msg string) { |
| 253 | statusCode := getStatusCode(err) |
| 254 | |
| 255 | rootErr := errors.Cause(err) |
| 256 | |
| 257 | var respText string |
| 258 | if pErr, ok := rootErr.(views.PublicError); ok { |
| 259 | respText = pErr.Public() |
| 260 | } else { |
| 261 | respText = http.StatusText(statusCode) |
| 262 | } |
| 263 | |
| 264 | logError(err, msg) |
| 265 | http.Error(w, respText, statusCode) |
| 266 | } |
| 267 | |
| 268 | // respondWithSession makes a HTTP response with the session from the user with the given userID. |
| 269 | // It sets the HTTP-Only cookie for browser clients and also sends a JSON response for non-browser clients. |
no test coverage detected