Current section

Files

Jump to
telega src telega@error.erl
Raw

src/telega@error.erl

-module(telega@error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/telega/error.gleam").
-export([to_string/1, 'try'/3]).
-export_type([telega_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type telega_error() :: {telegram_api_error, integer(), binary()} |
{fetch_error, binary()} |
{json_decode_error, gleam@json:decode_error()} |
{bot_handle_update_error, binary()} |
api_to_request_convert_error |
set_webhook_error |
no_session_settings_error |
{registry_start_error, binary()} |
{bot_start_error, gleam@otp@actor:start_error()} |
{chat_instance_start_error, gleam@otp@actor:start_error()} |
file_not_found_error |
{decode_update_error, binary()} |
{unknown_update_error, telega@model@types:update()} |
{actor_error, binary()} |
{router_error, binary()}.
-file("src/telega/error.gleam", 42).
-spec to_string(telega_error()) -> binary().
to_string(Error) ->
case Error of
{telegram_api_error, Error_code, Description} ->
<<<<<<"Telegram API error: "/utf8,
(erlang:integer_to_binary(Error_code))/binary>>/binary,
" "/utf8>>/binary,
Description/binary>>;
{json_decode_error, Error@1} ->
<<"Decode JSON error: "/utf8,
(gleam@string:inspect(Error@1))/binary>>;
api_to_request_convert_error ->
<<"Failed to convert API request to HTTP request"/utf8>>;
{fetch_error, Error@2} ->
<<"Failed to send request: "/utf8,
(gleam@string:inspect(Error@2))/binary>>;
set_webhook_error ->
<<"Failed to set webhook"/utf8>>;
no_session_settings_error ->
<<"Session settings not initialized"/utf8>>;
{registry_start_error, Reason} ->
<<"Failed to start registry: "/utf8, Reason/binary>>;
{bot_start_error, Reason@1} ->
<<"Failed to start bot: "/utf8,
(gleam@string:inspect(Reason@1))/binary>>;
{chat_instance_start_error, Reason@2} ->
<<"Failed to start chat instance: "/utf8,
(gleam@string:inspect(Reason@2))/binary>>;
file_not_found_error ->
<<"File not found"/utf8>>;
{decode_update_error, Reason@3} ->
<<"Failed to decode update: "/utf8, Reason@3/binary>>;
{bot_handle_update_error, Reason@4} ->
<<"Failed to handle update: "/utf8, Reason@4/binary>>;
{unknown_update_error, Update} ->
<<"Unknown update: "/utf8, (gleam@string:inspect(Update))/binary>>;
{actor_error, Reason@5} ->
<<"Actor error: "/utf8, Reason@5/binary>>;
{router_error, Reason@6} ->
<<"Router error: "/utf8, Reason@6/binary>>
end.
-file("src/telega/error.gleam", 65).
?DOC(" Helper to replace `result.try` for api call and error mapping.\n").
-spec 'try'(
{ok, UCE} | {error, telega_error()},
fun((telega_error()) -> UCH),
fun((UCE) -> {ok, UCI} | {error, UCH})
) -> {ok, UCI} | {error, UCH}.
'try'(Result, To_error, Fun) ->
case Result of
{ok, X} ->
Fun(X);
{error, E} ->
{error, To_error(E)}
end.