-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Massive overhaul to errors API
- Loading branch information
1 parent
5e4aa2f
commit 3d2480d
Showing
13 changed files
with
238 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
package dominos | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var ( | ||
InvalidCountry = errors.New("invalid country code") | ||
GenericError = errors.New("An unknown error has occurred. Please contact WiiLink support\nError Code: ") | ||
) | ||
|
||
func MakeError(err map[string]any) error { | ||
// Dominos error system is quite confusing, the more people that encounter errors the more we will learn. | ||
statuses := err["Order"].(map[string]any)["StatusItems"].([]any) | ||
|
||
for _, status := range statuses { | ||
// Our implementation should always have the first dictionary be "AutoAddedOrderId". | ||
// To be safe we will skip if encountered. | ||
code := status.(map[string]any)["Code"].(string) | ||
if code == "AutoAddedOrderId" { | ||
continue | ||
} | ||
|
||
// This is not guaranteed to exist. If it does, it is much more verbose than the code. | ||
pulseText := status.(map[string]any)["PulseText"] | ||
if pulseText != nil { | ||
return errors.New(fmt.Sprintf("An error has occured: %s\nError Code: ", pulseText)) | ||
} | ||
|
||
// Default to the error code | ||
return errors.New(fmt.Sprintf("An error has occured: %s\nError Code: ", code)) | ||
} | ||
|
||
// If somehow nothing existed, give generic error. | ||
return GenericError | ||
} |
Oops, something went wrong.