(value interface{})
| 1616 | } |
| 1617 | |
| 1618 | func (h *handler) addJSON(value interface{}) error { |
| 1619 | encoder := base.JSONEncoderCanonical(h.response) |
| 1620 | err := encoder.Encode(value) |
| 1621 | if err != nil { |
| 1622 | brokenPipeError := strings.Contains(err.Error(), "write: broken pipe") |
| 1623 | connectionResetError := strings.Contains(err.Error(), "write: connection reset") |
| 1624 | if brokenPipeError || connectionResetError { |
| 1625 | base.DebugfCtx(h.ctx(), base.KeyCRUD, "Couldn't serialize document body, HTTP client closed connection") |
| 1626 | return err |
| 1627 | } else { |
| 1628 | base.WarnfCtx(h.ctx(), "Couldn't serialize JSON for %s", err) |
| 1629 | h.writeStatus(http.StatusInternalServerError, "Couldn't serialize document body") |
| 1630 | } |
| 1631 | } |
| 1632 | return nil |
| 1633 | } |
| 1634 | |
| 1635 | func (h *handler) writeMultipart(subtype string, callback func(*multipart.Writer) error) error { |
| 1636 | if !h.requestAccepts("multipart/") { |
no test coverage detected