-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfae687
commit 0970184
Showing
37 changed files
with
14,249 additions
and
10,976 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package core | ||
|
||
import "fmt" | ||
|
||
// APIError is a lightweight wrapper around the standard error | ||
// interface that preserves the status code from the RPC, if any. | ||
type APIError struct { | ||
err error | ||
|
||
StatusCode int `json:"-"` | ||
} | ||
|
||
// NewAPIError constructs a new API error. | ||
func NewAPIError(statusCode int, err error) *APIError { | ||
return &APIError{ | ||
err: err, | ||
StatusCode: statusCode, | ||
} | ||
} | ||
|
||
// Unwrap returns the underlying error. This also makes the error compatible | ||
// with errors.As and errors.Is. | ||
func (a *APIError) Unwrap() error { | ||
if a == nil { | ||
return nil | ||
} | ||
return a.err | ||
} | ||
|
||
// Error returns the API error's message. | ||
func (a *APIError) Error() string { | ||
if a == nil || (a.err == nil && a.StatusCode == 0) { | ||
return "" | ||
} | ||
if a.err == nil { | ||
return fmt.Sprintf("%d", a.StatusCode) | ||
} | ||
if a.StatusCode == 0 { | ||
return a.err.Error() | ||
} | ||
return fmt.Sprintf("%d: %s", a.StatusCode, a.err.Error()) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package core | ||
|
||
import "net/http" | ||
|
||
// HTTPClient is an interface for a subset of the *http.Client. | ||
type HTTPClient interface { | ||
Do(*http.Request) (*http.Response, error) | ||
} |
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
Oops, something went wrong.