Refactor dets repo, dockerfile, and url type; add logger level func

This commit is contained in:
mitchell 2019-12-15 23:20:21 -05:00
parent faaf12ba42
commit fe413d2a5e
5 changed files with 19 additions and 6 deletions

View file

@ -46,7 +46,7 @@ defmodule Shortnr.Router do
end
def handle_errors(conn, %{kind: _kind, reason: reason, stack: stack}) do
Logger.error(inspect(reason), stack: inspect(stack))
Logger.error(reason, stack: stack)
{:error, {:internal_server_error, "internal server error"}, conn}
|> Text.encode_response()

View file

@ -3,7 +3,10 @@ defmodule Shortnr.URL.Repo.DETS do
@impl true
def get(key) do
{:ok, :dets.lookup(:urls, key) |> List.first() |> elem(1)}
case :dets.lookup(:urls, key) |> List.first() do
{_, url} -> {:ok, url}
nil -> {:ok, nil}
end
end
@impl true

View file

@ -8,7 +8,12 @@ defmodule Shortnr.URL do
updated_at: DateTime.utc_now(),
url: %URI{}
@type t :: %__MODULE__{id: String.t(), url: URI.t()}
@type t :: %__MODULE__{
id: String.t(),
url: URI.t(),
created_at: DateTime.t(),
updated_at: DateTime.t()
}
@spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error()
def create(url, repo) do