MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / writeStatus

Method writeStatus

rest/handler.go:1685–1711  ·  view source on GitHub ↗

Writes the response status code, and if it's an error writes a JSON description to the body.

(status int, message string)

Source from the content-addressed store, hash-verified

1683
1684// Writes the response status code, and if it's an error writes a JSON description to the body.
1685func (h *handler) writeStatus(status int, message string) {
1686 if status < 300 {
1687 h.response.WriteHeader(status)
1688 h.setStatus(status, message)
1689 return
1690 }
1691 // Got an error:
1692 var errorStr string
1693 switch status {
1694 case http.StatusNotFound:
1695 errorStr = "not_found"
1696 case http.StatusConflict:
1697 errorStr = "conflict"
1698 default:
1699 errorStr = http.StatusText(status)
1700 if errorStr == "" {
1701 errorStr = fmt.Sprintf("%d", status)
1702 }
1703 }
1704
1705 h.disableResponseCompression()
1706 h.setHeader("Content-Type", "application/json")
1707 h.response.WriteHeader(status)
1708 h.setStatus(status, message)
1709
1710 _, _ = h.response.Write([]byte(`{"error":"` + errorStr + `","reason":` + base.ConvertToJSONString(message) + `}`))
1711}
1712
1713var kRangeRegex = regexp.MustCompile("^bytes=(\\d+)?-(\\d+)?$")
1714

Callers 10

updatePrincipalMethod · 0.95
putReplicationMethod · 0.95
writeJSONStatusMethod · 0.95
writeRawJSONStatusMethod · 0.95
addJSONMethod · 0.95
writeErrorMethod · 0.95
handlePutDesignDocMethod · 0.95
handleAllDocsMethod · 0.95
wrapRouterFunction · 0.80

Calls 6

setStatusMethod · 0.95
setHeaderMethod · 0.95
ConvertToJSONStringFunction · 0.92
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected