Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
end
end
- # Write error as JSON and set the right content type header.
- fun json_error(error: nullable Serializable, status: nullable Int) do
- json(error, status)
+ # Write error as JSON.
+ #
+ # Format: `{"message": message, "status": status}`
+ fun json_error(message: String, status: Int) do
+ var obj = new JsonObject
+ obj["status"] = status
+ obj["message"] = message
+ json(obj, status)
end
# Redirect response to `location`
# redef fun post(req, res) do
# var validator = new BookValidator
# if not validator.validate(req.body) then
-# res.json_error(validator.validation, 400)
+# res.json(validator.validation, 400)
# return
# end
# # TODO data persistence
#
# Errors messages are grouped into *scopes*. A scope is a string that specify wich
# field or document the error message is related to.
-#
-# See `HttpResponse::json_error`.
class ValidationResult
super Jsonable