Skip to content

Commit

Permalink
ex_tldr: raise exceptions if request fail
Browse files Browse the repository at this point in the history
If the request failed first check if it is because there is not internet
connection, if true, raise an NoInternetConnectionError, if it is not
the error, it raise an UnexpectedError and report to the user the error,
encouraging to report it in the official repository.
  • Loading branch information
ivanhercaz committed Jun 21, 2020
1 parent 1e1fa1f commit 740819f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/ex_tldr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ defmodule ExTldr do
IO.puts("Term not found on \"common\" pages.")
end

{:error, %HTTPoison.Error{reason: reason}} ->
IO.inspect(reason)
{:error, %HTTPoison.Error{reason: reason}} when reason == :nxdomain ->
raise NoInternetConnectionError

{:error, %HTTPoison.Error{reason: reason}} when reason != :nxdomain ->
raise UnexpectedError, reason
end
end
end

0 comments on commit 740819f

Please sign in to comment.