writeErrorResponse will respond to the eyeball with basic HTTP JSON payloads with validation failure information
(w http.ResponseWriter, errResp managementError)
| 51 | |
| 52 | // writeErrorResponse will respond to the eyeball with basic HTTP JSON payloads with validation failure information |
| 53 | func writeHTTPErrorResponse(w http.ResponseWriter, errResp managementError) { |
| 54 | w.Header().Set("Content-Type", "application/json") |
| 55 | w.WriteHeader(http.StatusBadRequest) |
| 56 | err := json.NewEncoder(w).Encode(managementErrorResponse{ |
| 57 | Success: false, |
| 58 | Errors: []managementError{errResp}, |
| 59 | }) |
| 60 | // we have already written the header, so write a basic error response if unable to encode the error |
| 61 | if err != nil { |
| 62 | // fallback to text message |
| 63 | http.Error(w, fmt.Sprintf( |
| 64 | "%d %s", |
| 65 | http.StatusBadRequest, |
| 66 | http.StatusText(http.StatusBadRequest), |
| 67 | ), http.StatusBadRequest) |
| 68 | } |
| 69 | } |
no test coverage detected