-
Notifications
You must be signed in to change notification settings - Fork 1
/
oautherror.go
31 lines (27 loc) · 1.14 KB
/
oautherror.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package jsonclient
import (
"fmt"
"net/http"
)
// JCOAuthError lets us easily decode an oautherror response from a service we call,
// and keep track of the error code for clients
// NOTE: this is very similar but different to `ucerr.OAuthError` because our usage
// here is very limited (we're duplicating ~8 lines of code), and it prevents a weird
// pass-through bug when a UC service gets an OAuthError from another service (say that
// Plex calls Auth0 and gets an OAuthError), wraps it, and then accidentally returns the
// wrapped-service error code automatically (rather than the one Plex should set)
type oAuthError struct {
ErrorType string `json:"error"`
ErrorDesc string `json:"error_description,omitempty"`
Code int `json:"-"`
}
// Error implements interface `error` for type `OAuthError`
func (o oAuthError) Error() string {
return fmt.Sprintf("%s: %s [http status: %d]", o.ErrorType, o.ErrorDesc, o.Code)
}
// ErrIncorrectUsernamePassword indicates a bad username or password.
var ErrIncorrectUsernamePassword = oAuthError{
ErrorType: "invalid_grant",
ErrorDesc: "incorrect username or password",
Code: http.StatusBadRequest,
}