Simplifying error response writing for object handlers

This commit is contained in:
Frederick F. Kautz IV
2015-03-29 22:03:10 -07:00
parent c3cda5d9a8
commit 7d657eb55c
2 changed files with 28 additions and 139 deletions
+11
View File
@@ -142,3 +142,14 @@ func ignoreUnImplementedObjectResources(req *http.Request) bool {
}
return false
}
func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int, acceptsContentType contentType, resource string) {
error := getErrorCode(errorType)
errorResponse := getErrorResponse(error, resource)
// set headers
setCommonHeaders(w, getContentTypeString(acceptsContentType))
w.WriteHeader(error.HTTPStatusCode)
// write body
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
w.Write(encodedErrorResponse)
}