Skip to content

Commit

Permalink
Auto-merge for PR balena-io#566 via VersionBot
Browse files Browse the repository at this point in the history
462 narrow catch clauses
  • Loading branch information
resin-io-versionbot[bot] authored Aug 20, 2018
2 parents 5fed01c + da699d5 commit e0406c2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v10.0.7 - 2018-08-20

* Change name and logic of normalizeAuthError method #566 [amdomanska]
* Report authentication errors more accurately #566 [Tim Perry]

## v10.0.6 - 2018-08-17

* Add support for 'all' in logs requests #556 [Tim Perry]
Expand Down
17 changes: 12 additions & 5 deletions lib/auth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ getAuth = (deps, opts) ->
twoFactor = require('./2fa')(deps, opts)
exports = {}

normalizeAuthError = (err) ->
if err.statusCode == 401
return new errors.ResinNotLoggedIn()
else if err.code == 'ResinMalformedToken'
return new errors.ResinNotLoggedIn()
else
return err

###*
# @namespace resin.auth.twoFactor
# @memberof resin.auth
Expand All @@ -41,8 +49,8 @@ getAuth = (deps, opts) ->
.get('body')
.tap (body) ->
userDetailsCache = body
.catch ->
throw new errors.ResinNotLoggedIn()
.catch (err) ->
throw normalizeAuthError(err)

###*
# @summary Return current logged in username
Expand Down Expand Up @@ -240,10 +248,9 @@ getAuth = (deps, opts) ->
exports.getToken = (callback) ->
auth.getKey()
.then (savedToken) ->
throw new errors.ResinNotLoggedIn() if not savedToken?
return savedToken
.catch ->
throw new errors.ResinNotLoggedIn()
.catch (err) ->
throw normalizeAuthError(err)
.asCallback(callback)

###*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resin-sdk",
"version": "10.0.6",
"version": "10.0.7",
"description": "The Resin.io JavaScript SDK",
"main": "build/resin.js",
"types": "typings/resin-sdk.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/auth.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ describe 'SDK authentication', ->

m.chai.expect(promise).to.be.rejectedWith('Unauthorized')

describe 'resin.auth.getToken()', ->

it 'should be rejected', ->
promise = resin.auth.getToken()
m.chai.expect(promise).to.be.rejected
.and.eventually.have.property('code', 'ResinNotLoggedIn')

describe 'resin.auth.loginWithToken()', ->

it 'should be able to login with a session token', ->
Expand Down Expand Up @@ -122,6 +129,7 @@ describe 'SDK authentication', ->

m.chai.expect(promise).to.be.rejectedWith('This email is already taken')


describe 'when logged in with credentials', ->

givenLoggedInUser()
Expand Down

0 comments on commit e0406c2

Please sign in to comment.