lib/popcorn: add `json_error` to return a Json formatted error
[nit.git] / lib / popcorn / pop_handlers.nit
index 5d84961..1a22db6 100644 (file)
@@ -458,6 +458,11 @@ redef class HttpResponse
                end
        end
 
+       # Write error as JSON and set the right content type header.
+       fun json_error(error: nullable Jsonable, status: nullable Int) do
+               json(error, status)
+       end
+
        # Redirect response to `location`
        fun redirect(location: String, status: nullable Int) do
                header["Location"] = location