mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00
Merge pull request #146 from mainflux/issue-145
Fix 403 errors handling
This commit is contained in:
commit
411cbf575a
@ -130,7 +130,7 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
case errUnknownType:
|
||||
w.WriteHeader(http.StatusUnsupportedMediaType)
|
||||
case errUnauthorizedAccess:
|
||||
case manager.ErrUnauthorizedAccess:
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
default:
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
@ -18,8 +18,14 @@ const (
|
||||
maxFailureRatio = 0.6
|
||||
)
|
||||
|
||||
// ErrServiceUnreachable indicates that the service instance is not available.
|
||||
var ErrServiceUnreachable = errors.New("manager service unavailable")
|
||||
var (
|
||||
// ErrServiceUnreachable indicates that the service instance is not available.
|
||||
ErrServiceUnreachable = errors.New("manager service unavailable")
|
||||
|
||||
// ErrUnauthorizedAccess indicates missing or invalid credentials provided
|
||||
// when accessing a protected resource.
|
||||
ErrUnauthorizedAccess = manager.ErrUnauthorizedAccess
|
||||
)
|
||||
|
||||
// ManagerClient provides an access to the manager service authorization
|
||||
// endpoints.
|
||||
@ -79,7 +85,7 @@ func (mc ManagerClient) makeRequest(url, token string) (string, error) {
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return manager.ErrUnauthorizedAccess, nil
|
||||
return ErrUnauthorizedAccess, nil
|
||||
}
|
||||
|
||||
return res.Header.Get("X-client-id"), nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user