From bb9650f3c26c0a6155cfb15f5e4da8257316661a Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 17 Nov 2020 16:43:07 +0100 Subject: [PATCH] FrontendController: Return error on installation error. --- lib/pleroma/frontend.ex | 2 ++ .../controllers/frontend_controller.ex | 6 +++--- .../operations/admin/frontend_operation.ex | 3 ++- .../controllers/frontend_controller_test.exs | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/frontend.ex b/lib/pleroma/frontend.ex index b3d4c3325..bf935a728 100644 --- a/lib/pleroma/frontend.ex +++ b/lib/pleroma/frontend.ex @@ -42,9 +42,11 @@ defmodule Pleroma.Frontend do else {:download_or_unzip, _} -> Logger.info("Could not download or unzip the frontend") + {:error, "Could not download or unzip the frontend"} _e -> Logger.info("Could not install the frontend") + {:error, "Could not install the frontend"} end end diff --git a/lib/pleroma/web/admin_api/controllers/frontend_controller.ex b/lib/pleroma/web/admin_api/controllers/frontend_controller.ex index 4518bed5a..fac3522b8 100644 --- a/lib/pleroma/web/admin_api/controllers/frontend_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/frontend_controller.ex @@ -29,9 +29,9 @@ defmodule Pleroma.Web.AdminAPI.FrontendController do end def install(%{body_params: params} = conn, _params) do - Pleroma.Frontend.install(params.name, Map.delete(params, :name)) - - index(conn, %{}) + with :ok <- Pleroma.Frontend.install(params.name, Map.delete(params, :name)) do + index(conn, %{}) + end end defp installed do diff --git a/lib/pleroma/web/api_spec/operations/admin/frontend_operation.ex b/lib/pleroma/web/api_spec/operations/admin/frontend_operation.ex index 9d7d017a2..96d4cdee7 100644 --- a/lib/pleroma/web/api_spec/operations/admin/frontend_operation.ex +++ b/lib/pleroma/web/api_spec/operations/admin/frontend_operation.ex @@ -36,7 +36,8 @@ defmodule Pleroma.Web.ApiSpec.Admin.FrontendOperation do requestBody: request_body("Parameters", install_request(), required: true), responses: %{ 200 => Operation.response("Response", "application/json", list_of_frontends()), - 403 => Operation.response("Forbidden", "application/json", ApiError) + 403 => Operation.response("Forbidden", "application/json", ApiError), + 400 => Operation.response("Error", "application/json", ApiError) } } end diff --git a/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs b/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs index db28a27b6..94873f6db 100644 --- a/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs @@ -118,5 +118,24 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"])) end + + test "failing returns an error", %{conn: conn} do + Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} -> + %Tesla.Env{status: 404, body: ""} + end) + + result = + conn + |> put_req_header("content-type", "application/json") + |> post("/api/pleroma/admin/frontends/install", %{ + name: "unknown", + ref: "baka", + build_url: "http://gensokyo.2hu/madeup.zip", + build_dir: "" + }) + |> json_response_and_validate_schema(400) + + assert result == %{"error" => "Could not download or unzip the frontend"} + end end end -- 2.45.2