ReadJSONFromMIME parses a JSON MIME body, unmarshalling it into "into". Closes the input io.ReadCloser once done.
(headers http.Header, input io.ReadCloser, into interface{})
| 39 | // ReadJSONFromMIME parses a JSON MIME body, unmarshalling it into "into". |
| 40 | // Closes the input io.ReadCloser once done. |
| 41 | func ReadJSONFromMIME(headers http.Header, input io.ReadCloser, into interface{}) error { |
| 42 | err := ReadJSONFromMIMERawErr(headers, input, into) |
| 43 | if err != nil { |
| 44 | err = base.WrapJSONUnknownFieldErr(err) |
| 45 | if errors.Cause(err) == base.ErrUnknownField { |
| 46 | err = base.HTTPErrorf(http.StatusBadRequest, "JSON Unknown Field: %s", err.Error()) |
| 47 | } else { |
| 48 | err = base.HTTPErrorf(http.StatusBadRequest, "Bad JSON: %s", err.Error()) |
| 49 | } |
| 50 | } |
| 51 | return err |
| 52 | } |
| 53 | |
| 54 | func ReadJSONFromMIMERawErr(headers http.Header, input io.ReadCloser, into interface{}) error { |
| 55 | input, err := processContentEncoding(headers, input, "application/json") |