Skip to content

Commit bd4cead

Browse files
authored
Merge pull request #2 from Cellane/patch-2
Stopped middleware from eating custom HTTP headers
2 parents 14f95e0 + 3ee162b commit bd4cead

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/APIErrorMiddleware/APIErrorMiddleware.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
5858
// for the response returned by the
5959
// middleware.
6060
var result: ErrorResult!
61+
62+
// The HTTP headers to send with the error
63+
var headers: HTTPHeaders = ["Content-Type": "application/json"]
64+
6165

6266
// Loop through the specializations, running
6367
// the error converter on each one.
@@ -78,6 +82,10 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
7882
// status code and error message.
7983
// Assign the data to the correct varaibles.
8084
result = ErrorResult(message: abort.reason, status: abort.status)
85+
86+
abort.headers.forEach { name, value in
87+
headers.add(name: name, value: value)
88+
}
8189
case let debuggable as Debuggable where !self.environment.isRelease:
8290
// Since we are not in a production environment and we
8391
// have a error conforming to `Debuggable`, we get the
@@ -119,7 +127,7 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
119127
// A body with the JSON we created.
120128
let httpResponse = HTTPResponse(
121129
status: result.status ?? .badRequest,
122-
headers: ["Content-Type": "application/json"],
130+
headers: headers,
123131
body: HTTPBody(data: json)
124132
)
125133

0 commit comments

Comments
 (0)