protonmail: export ApiError

This commit is contained in:
emersion 2018-01-09 22:58:42 +01:00
parent ed67f2a3f5
commit dea3ab3106
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 11 additions and 5 deletions

View File

@ -24,8 +24,10 @@ type resp struct {
func (r *resp) Err() error { func (r *resp) Err() error {
if err := r.apiError; err != nil { if err := r.apiError; err != nil {
err.code = r.Code return &ApiError{
return err Code: r.Code,
Message: err.Message,
}
} }
return nil return nil
} }
@ -35,12 +37,16 @@ type maybeError interface {
} }
type apiError struct { type apiError struct {
code int // populated by resp
Message string `json:"Error"` Message string `json:"Error"`
} }
func (err apiError) Error() string { type ApiError struct {
return fmt.Sprintf("[%v] %v", err.code, err.Message) Code int
Message string
}
func (err *ApiError) Error() string {
return fmt.Sprintf("[%v] %v", err.Code, err.Message)
} }
// Client is a ProtonMail API client. // Client is a ProtonMail API client.