1
0
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:
Drasko DRASKOVIC 2018-01-26 20:56:05 +01:00 committed by GitHub
commit 411cbf575a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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)

View File

@ -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