1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-08 10:39:17 +00:00

More initial dev

This commit is contained in:
Darren Shepherd
2017-11-10 21:44:02 -07:00
parent c06696a1e4
commit c8cab3f4f8
72 changed files with 5674 additions and 1211 deletions

35
httperror/handler.go Normal file
View File

@@ -0,0 +1,35 @@
package httperror
import (
"github.com/rancher/norman/types"
"github.com/sirupsen/logrus"
)
func ErrorHandler(request *types.APIContext, err error) {
var error *APIError
if apiError, ok := err.(*APIError); ok {
error = apiError
} else {
logrus.Errorf("Unknown error: %v", err)
error = &APIError{
code: SERVER_ERROR,
message: err.Error(),
}
}
data := toError(error)
request.WriteResponse(error.code.status, data)
}
func toError(apiError *APIError) map[string]interface{} {
e := map[string]interface{}{
"type": "/v3/schema",
"code": apiError.code.code,
"message": apiError.message,
}
if apiError.fieldName != "" {
e["fieldName"] = apiError.fieldName
}
return e
}