In Chapter 7’s Fluent queries→Filter section, there is some example code:
guard let searchTerm =
req.query[String.self, at: "term"] else {
throw Abort(.badRequest)
}
My question is why not simply use:
let searchTerm = try req.query.get(String.self, at: "term")
This approach also throws a 500/bad request error however the message is more descriptive:
{
"error": true,
"reason": "Value of type 'String' required for key 'term'."
}
Is this just an accidental oversight on the author’s part, or is there good reason to not do it this way?