Skip to content

Commit 5867edb

Browse files
committed
fix: try fix error
1 parent 3d55e0c commit 5867edb

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

Sources/ErrorMiddleware/Extensions/HTTPConvertibleAppError+Extensions.swift

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@ import Vapor
99
import HTTPTypes
1010
import OpenAPIRuntime
1111

12-
//extension HTTPConvertibleAppError {
13-
// var httpStatus: HTTPResponse.Status {
14-
// HTTPResponse.Status(code: Int(status.code), reasonPhrase: status.reasonPhrase)
15-
// }
16-
//
17-
// var httpHeaderFields: HTTPFields {
18-
// var fields = HTTPFields()
19-
// fields.append(HTTPField(name: .contentType, value: "application/json; charset=utf-8"))
20-
// return fields
21-
// }
22-
//
23-
// var httpBody: HTTPBody? {
24-
// let payload = ErrorResponse(
25-
// reason: reason,
26-
// error: identifier,
27-
// status: "\(httpStatus.code) \(httpStatus.reasonPhrase)",
28-
// code: number
29-
// )
30-
// guard let data = try? JSONEncoder().encode(payload) else { return nil }
31-
// return HTTPBody(data)
32-
// }
33-
//}
12+
public extension HTTPConvertibleAppError {
13+
var httpStatus: HTTPResponse.Status {
14+
HTTPResponse.Status(code: Int(status.code), reasonPhrase: status.reasonPhrase)
15+
}
16+
17+
var httpHeaderFields: HTTPFields {
18+
var fields = HTTPFields()
19+
fields.append(HTTPField(name: .contentType, value: "application/json; charset=utf-8"))
20+
return fields
21+
}
22+
23+
var httpBody: HTTPBody? {
24+
let payload = ErrorResponse(
25+
isError: true,
26+
reason: reason,
27+
error: identifier,
28+
status: httpStatus.code.description,
29+
code: "\(httpStatus.code).\(number).\(httpStatus.reasonPhrase)"
30+
)
31+
guard let data = try? JSONEncoder().encode(payload) else { return nil }
32+
return HTTPBody(data)
33+
}
34+
}

Sources/ErrorMiddleware/Utilities/HTTPConvertibleAppError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
import OpenAPIRuntime
99

10-
protocol HTTPConvertibleAppError: AppError, HTTPResponseConvertible {}
10+
public protocol HTTPConvertibleAppError: AppError, HTTPResponseConvertible {}

0 commit comments

Comments
 (0)