lib/popcorn: replace json_error method by something more useful
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 12 May 2017 01:47:58 +0000 (21:47 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 12 May 2017 01:49:54 +0000 (21:49 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/popcorn/pop_handlers.nit
lib/popcorn/pop_validation.nit

index 8824db0..6b1e825 100644 (file)
@@ -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`
index b1464b8..86860e5 100644 (file)
@@ -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