Skip to content

Commit

Permalink
Improve MongoosePush's logs on 4xx errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rslota committed Mar 20, 2018
1 parent 43ebd25 commit 85938cb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/mod_push_service_mongoosepush.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ http_notification(Host, Method, URL, ReqHeaders, Payload) ->
Pool = mongoose_http_client:get_pool(PoolName),
case mongoose_http_client:Method(Pool, URL, ReqHeaders, Payload) of
{ok, {BinStatusCode, Body}} ->
StatusCode = binary_to_integer(BinStatusCode),
case StatusCode >= 200 andalso StatusCode < 300 of
true -> ok;
false ->
case binary_to_integer(BinStatusCode) of
StatusCode when StatusCode >= 200 andalso StatusCode < 300 ->
ok;
StatusCode when StatusCode >= 400 andalso StatusCode < 500 ->
?ERROR_MSG("Unable to submit push notification. ErrorCode ~p, Payload ~p.",
"Possible API mismatch - tried URL: ~p.",
[StatusCode, Payload, URL]),
{error, {invalid_status_code, StatusCode}};
StatusCode ->
?WARNING_MSG("Unable to submit push notification. ErrorCode ~p, Payload ~p",
[StatusCode, Body]),
{error, {invalid_status_code, StatusCode}}
Expand Down

0 comments on commit 85938cb

Please sign in to comment.