move providers into providers subdirectory
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
40
providers/questrade/errors.go
Normal file
40
providers/questrade/errors.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package questrade
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type QuestradeError struct {
|
||||
Code int `json:"code"`
|
||||
StatusCode int
|
||||
Message string `json:"message"`
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
func newQuestradeError(res *http.Response, body []byte) QuestradeError {
|
||||
// Unmarshall the error text
|
||||
var e QuestradeError
|
||||
err := json.Unmarshal(body, &e)
|
||||
if err != nil {
|
||||
e.Code = -999
|
||||
e.Message = string(body)
|
||||
}
|
||||
|
||||
e.StatusCode = res.StatusCode
|
||||
e.Endpoint = res.Request.URL.String()
|
||||
return e
|
||||
}
|
||||
|
||||
func (q QuestradeError) Error() string {
|
||||
return fmt.Sprintf("\nQuestradeError:\n"+
|
||||
"\tStatus code: HTTP %d\n"+
|
||||
"\tEndpoint: %s\n"+
|
||||
"\tError code: %d\n"+
|
||||
"\tMessage: %s\n",
|
||||
q.StatusCode,
|
||||
q.Endpoint,
|
||||
q.Code,
|
||||
q.Message)
|
||||
}
|
Reference in New Issue
Block a user