Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rest/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func Error(w ResponseWriter, error string, code int) {
}
}

// ErrorCustom produces a custom error response in JSON with the custom structure,
// e.g. '{"Code": "1001", "Error":"My error message"}'
func ErrorCustom(w ResponseWriter, error interface{}, code int) {
w.WriteHeader(code)
err := w.WriteJson(error)
if err != nil {
panic(err)
}
}

// NotFound produces a 404 response with the following JSON, '{"Error":"Resource not found"}'
// The standard plain text net/http NotFound helper can still be called like this:
// http.NotFound(w, r.Request)
Expand Down