I want to create a custom server response for my controllers and my errors.
Here is the model:
struct ServerResponse<T: Content>: Content {
let code: Int
let message: String
let data: T?
}
My create request:
func create(_ req: Request) throws -> Future<ServerResponse<User>> {
try req.content.decode(User.self).flatMap { user in
user.save(on: req).map { user in
ServerResponse(code: ?, message: ?, data: user)
}
}
}
In case of success, how can I get the HTTPStatus code to add it to the Response?
And the message if success is OK, if the error is a custom description or the description of the HTTPStatus.