FrontendController: Return error on installation error.
authorlain <lain@soykaf.club>
Tue, 17 Nov 2020 15:43:07 +0000 (16:43 +0100)
committerlain <lain@soykaf.club>
Tue, 17 Nov 2020 15:43:07 +0000 (16:43 +0100)
lib/pleroma/frontend.ex
lib/pleroma/web/admin_api/controllers/frontend_controller.ex
lib/pleroma/web/api_spec/operations/admin/frontend_operation.ex
test/pleroma/web/admin_api/controllers/frontend_controller_test.exs

index b3d4c3325073f21b6ec33c9115c17d842844cc70..bf935a72855e2c6587458dae510454504dba58fe 100644 (file)
@@ -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
 
index 4518bed5a446c08839c08374967640175799a9c7..fac3522b83fef3bc2576eb859a66a234947db909 100644 (file)
@@ -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
index 9d7d017a2300ded18ec37a8f258864f430a26d39..96d4cdee7cd3c9fb7e6ec6f629b53aeea1a6c0b9 100644 (file)
@@ -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
index db28a27b6de8a891dd4e4b2bed62bf95a70b5548..94873f6dbc9afa4e5657eac3f04ddbdadec090eb 100644 (file)
@@ -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