@@ -58,6 +58,10 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
58
58
// for the response returned by the
59
59
// middleware.
60
60
var result : ErrorResult !
61
+
62
+ // The HTTP headers to send with the error
63
+ var headers : HTTPHeaders = [ " Content-Type " : " application/json " ]
64
+
61
65
62
66
// Loop through the specializations, running
63
67
// the error converter on each one.
@@ -78,6 +82,10 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
78
82
// status code and error message.
79
83
// Assign the data to the correct varaibles.
80
84
result = ErrorResult ( message: abort. reason, status: abort. status)
85
+
86
+ abort. headers. forEach { name, value in
87
+ headers. add ( name: name, value: value)
88
+ }
81
89
case let debuggable as Debuggable where !self . environment. isRelease:
82
90
// Since we are not in a production environment and we
83
91
// have a error conforming to `Debuggable`, we get the
@@ -119,7 +127,7 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
119
127
// A body with the JSON we created.
120
128
let httpResponse = HTTPResponse (
121
129
status: result. status ?? . badRequest,
122
- headers: [ " Content-Type " : " application/json " ] ,
130
+ headers: headers ,
123
131
body: HTTPBody ( data: json)
124
132
)
125
133
0 commit comments