Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Updated error handling for 500 API responses to print a more meaningf…
Browse files Browse the repository at this point in the history
…ul message for users
  • Loading branch information
ianmarmour committed Sep 21, 2020
1 parent 0669339 commit ef93182
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nvidia-clerk
nvidia-clerk.exe
nvidia-clerk-linux
nvidia-clerk-darwin
nvidia-clerk-windows.exe
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
TwilioConfig TwilioConfig
}

// Hardcoded SKU to locale/currency mappings to avoid user pain of having to lookup and enter these.
var skuBasedConfig = map[string]RegionalConfig{
"5438481700": {
SKU: "5438481700",
Expand Down
9 changes: 8 additions & 1 deletion internal/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -107,6 +108,12 @@ func GetSkuInfo(sku string, locale string, currency string, client *http.Client)
return nil, err
}

if r.StatusCode == 500 {
message := fmt.Sprintf("Rate Limited Exceeded for URL: %s", endpoint)
fmt.Println(message)
return nil, errors.New("Rate Limited Exceeded Error")
}

if r.Body != nil {
defer r.Body.Close()
}
Expand Down Expand Up @@ -150,7 +157,7 @@ func GetSkuInventory(sku string, locale string, client *http.Client) (*Inventory
inventory := Inventory{}
jsonErr := json.Unmarshal(body, &inventory)
if jsonErr != nil {
fmt.Println(jsonErr)
fmt.Println(fmt.Sprintf("Error decoding JSON response: %s", jsonErr))
return nil, jsonErr
}

Expand Down
Binary file removed nvidia-clerk-windows.exe
Binary file not shown.

0 comments on commit ef93182

Please sign in to comment.