summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-openapi/runtime/middleware/not_implemented.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-openapi/runtime/middleware/not_implemented.go')
-rw-r--r--vendor/github.com/go-openapi/runtime/middleware/not_implemented.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/vendor/github.com/go-openapi/runtime/middleware/not_implemented.go b/vendor/github.com/go-openapi/runtime/middleware/not_implemented.go
index 466f553db4..bc6942a0f1 100644
--- a/vendor/github.com/go-openapi/runtime/middleware/not_implemented.go
+++ b/vendor/github.com/go-openapi/runtime/middleware/not_implemented.go
@@ -38,11 +38,30 @@ func (e *errorResp) WriteResponse(rw http.ResponseWriter, producer runtime.Produ
rw.WriteHeader(http.StatusInternalServerError)
}
if err := producer.Produce(rw, e.response); err != nil {
- panic(err)
+ Logger.Printf("failed to write error response: %v", err)
}
}
// NotImplemented the error response when the response is not implemented
func NotImplemented(message string) Responder {
- return &errorResp{http.StatusNotImplemented, message, make(http.Header)}
+ return Error(http.StatusNotImplemented, message)
+}
+
+// Error creates a generic responder for returning errors, the data will be serialized
+// with the matching producer for the request
+func Error(code int, data interface{}, headers ...http.Header) Responder {
+ var hdr http.Header
+ for _, h := range headers {
+ for k, v := range h {
+ if hdr == nil {
+ hdr = make(http.Header)
+ }
+ hdr[k] = v
+ }
+ }
+ return &errorResp{
+ code: code,
+ response: data,
+ headers: hdr,
+ }
}