Skip to content

Commit

Permalink
Added custom responses for status codes as well as logging for errors. (
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansligh-nimbus authored Oct 22, 2024
1 parent 95ee792 commit 2338bd8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,28 @@ public async Task<string> MakeRequestAsync(BidRequest bidRequest) {
return "{\"message\": \"Application Closed\"}";
}
var nimbusResponse = await serverResponse.Content.ReadAsStringAsync();
#endif

if (nimbusResponse.IsNullOrEmpty())
{
switch ((int)serverResponse.StatusCode)
{
case 400:
nimbusResponse = "{\"status_code\": 400, \"message\": \"POST data was malformed\"}";
break;
case 404:
nimbusResponse = "{\"status_code\": 404,\"message\": \"No bids returned\"}";
break;
case 429:
nimbusResponse = "{\"status_code\": 429,\"message\": \"Rate limited\"}";
break;
case 500:
nimbusResponse = "{\"status_code\": 500,\"message\": \"Server is unavailable\"}";
break;
default:
nimbusResponse = $"{{\"status_code\": {(int)serverResponse.StatusCode},\"message\": \"Unknown network error occurred\"}}";
break;
}
}
#endif
return nimbusResponse;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,8 @@ await Task.Run(async () => {
try {
response = await jsonBody;
} catch (Exception e) { }

if (String.IsNullOrEmpty(response)) {
var networkError = new ErrResponse();
networkError.Id = "";
networkError.StatusCode = 0;
networkError.Message = "Unknown network error occurred";
ErrResponse = networkError;
_adEvents.FireOnAdErrorEvent(this);
return;
}
if (response.Contains("message")) {
Debug.unityLogger.Log("Nimbus",$"RESPONSE ERROR: {response}");
ErrResponse = JsonConvert.DeserializeObject<ErrResponse>(response);
_adEvents.FireOnAdErrorEvent(this);
return;
Expand Down

0 comments on commit 2338bd8

Please sign in to comment.