You've already forked focalboard
mirror of
https://github.com/mattermost/focalboard.git
synced 2025-07-15 23:54:29 +02:00
avoid panic in request error handling (#3528)
This commit is contained in:
@ -4587,7 +4587,7 @@ func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
setResponseHeader(w, "Content-Type", "application/json")
|
||||||
data, err := json.Marshal(model.ErrorResponse{Error: message, ErrorCode: code})
|
data, err := json.Marshal(model.ErrorResponse{Error: message, ErrorCode: code})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = []byte("{}")
|
data = []byte("{}")
|
||||||
@ -4597,18 +4597,26 @@ func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stringResponse(w http.ResponseWriter, message string) {
|
func stringResponse(w http.ResponseWriter, message string) {
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
setResponseHeader(w, "Content-Type", "text/plain")
|
||||||
_, _ = fmt.Fprint(w, message)
|
_, _ = fmt.Fprint(w, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonStringResponse(w http.ResponseWriter, code int, message string) {
|
func jsonStringResponse(w http.ResponseWriter, code int, message string) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
setResponseHeader(w, "Content-Type", "application/json")
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
fmt.Fprint(w, message)
|
fmt.Fprint(w, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonBytesResponse(w http.ResponseWriter, code int, json []byte) {
|
func jsonBytesResponse(w http.ResponseWriter, code int, json []byte) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
setResponseHeader(w, "Content-Type", "application/json")
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
_, _ = w.Write(json)
|
_, _ = w.Write(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setResponseHeader(w http.ResponseWriter, key string, value string) {
|
||||||
|
header := w.Header()
|
||||||
|
if header == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
header.Set(key, value)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user