implement error and healthh endpoints
All checks were successful
Build and Publish / build-release (push) Successful in 1m28s
All checks were successful
Build and Publish / build-release (push) Successful in 1m28s
This commit is contained in:
17
lib/provider_service_web/controllers/error_json.ex
Normal file
17
lib/provider_service_web/controllers/error_json.ex
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
defmodule ProviderServiceWeb.ErrorJSON do
|
||||||
|
@moduledoc """
|
||||||
|
This module is invoked by your endpoint in case of errors on JSON requests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render("404.json", _assigns) do
|
||||||
|
%{errors: %{detail: "Not Found"}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def render("500.json", _assigns) do
|
||||||
|
%{errors: %{detail: "Internal Server Error"}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def render(template, _assigns) do
|
||||||
|
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
|
||||||
|
end
|
||||||
|
end
|
||||||
15
lib/provider_service_web/controllers/health_controller.ex
Normal file
15
lib/provider_service_web/controllers/health_controller.ex
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule ProviderServiceWeb.HealthController do
|
||||||
|
use ProviderServiceWeb, :controller
|
||||||
|
|
||||||
|
def health(conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_status(:ok)
|
||||||
|
|> json(%{status: "ok"})
|
||||||
|
end
|
||||||
|
|
||||||
|
def ready(conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_status(:ok)
|
||||||
|
|> json(%{status: "ready"})
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,6 +6,9 @@ defmodule ProviderServiceWeb.Router do
|
|||||||
plug(OpenApiSpex.Plug.PutApiSpec, module: ProviderServiceWeb.ApiSpec)
|
plug(OpenApiSpex.Plug.PutApiSpec, module: ProviderServiceWeb.ApiSpec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get("/health", ProviderServiceWeb.HealthController, :health)
|
||||||
|
get("/health/ready", ProviderServiceWeb.HealthController, :ready)
|
||||||
|
|
||||||
scope "/api" do
|
scope "/api" do
|
||||||
pipe_through(:api)
|
pipe_through(:api)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user