@@ -9,25 +9,26 @@ import Vapor
99import HTTPTypes
1010import 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+ }
0 commit comments