From 9da15aed14755886da46663831dfa851b617d9b8 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 11 May 2017 21:47:58 -0400 Subject: [PATCH] lib/popcorn: replace json_error method by something more useful Signed-off-by: Alexandre Terrasa --- lib/popcorn/pop_handlers.nit | 11 ++++++++--- lib/popcorn/pop_validation.nit | 4 +--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/popcorn/pop_handlers.nit b/lib/popcorn/pop_handlers.nit index 8824db0..6b1e825 100644 --- a/lib/popcorn/pop_handlers.nit +++ b/lib/popcorn/pop_handlers.nit @@ -470,9 +470,14 @@ redef class HttpResponse 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` diff --git a/lib/popcorn/pop_validation.nit b/lib/popcorn/pop_validation.nit index b1464b8..86860e5 100644 --- a/lib/popcorn/pop_validation.nit +++ b/lib/popcorn/pop_validation.nit @@ -61,7 +61,7 @@ # 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 @@ -95,8 +95,6 @@ end # # 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 -- 1.7.9.5