Skip to content

Commit

Permalink
Handle few validation errors (#12)
Browse files Browse the repository at this point in the history
* Handle few validation errors

* Add 2 more error cases
  • Loading branch information
ziopio authored Oct 7, 2024
1 parent f9d620b commit 02a2b73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/rebar3_grisp_io_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ validate_update(RState, Token, Device) ->
{ok, 204, _, _} ->
ok;
{ok, 400, _, ClientRef} ->
{ok, _RespBody} = hackney:body(ClientRef),
error(unknown_request);
{ok, RespBody} = hackney:body(ClientRef),
#{<<"error">> := Error} = jsx:decode(RespBody),
throw({error, Error});
{ok, 401, _, _} ->
throw(wrong_credentials);
{ok, 403, _, _} ->
Expand Down
12 changes: 11 additions & 1 deletion src/rebar3_grisp_io_validate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ do(RState) ->

{ok, RState}
catch
throw:{error, <<"no_process">>} ->
abort("Error: no deployment process is running.");
throw:{error, <<"disconnected">>} ->
abort("Error: the device is not connected to GRiSP.io");
throw:{error, <<"validate_from_unbooted">>} ->
abort("Error: device needs to be rebooted.");
throw:{error, <<"wait_device">>} ->
abort("Error: deployment waiting for device");
throw:{error, <<"download">>} ->
abort("Error: the device is still downloading the updated");
throw:no_device_serial_number ->
abort("Error: The serial number of the target device is missing." ++
" Specify it with -d or --device");
Expand Down Expand Up @@ -87,6 +97,6 @@ try_get_device_serial(RState) ->
case rebar_state:command_args(RState) of
[] ->
throw(no_device_serial_number);
[Serial | _] ->
[Serial | _] ->
Serial
end.

0 comments on commit 02a2b73

Please sign in to comment.