diff --git a/packages/authentication/src/client/index.js b/packages/authentication/src/client/index.js index fa1c6ed7e2..0d0547b8df 100644 --- a/packages/authentication/src/client/index.js +++ b/packages/authentication/src/client/index.js @@ -1,5 +1,6 @@ import * as hooks from './hooks'; import { connected, authenticateSocket, getJWT, getStorage } from './utils'; +import errors from 'feathers-errors'; const defaults = { tokenKey: 'feathers-jwt', @@ -25,7 +26,7 @@ export default function(opts = {}) { if (!options.type) { getOptions = getJWT(config.tokenKey, this.get('storage')).then(token => { if (!token) { - return Promise.reject(new Error(`Could not find stored JWT and no authentication type was given`)); + return Promise.reject(new errors.NotAuthenticated(`Could not find stored JWT and no authentication type was given`)); } return { type: 'token', token }; diff --git a/packages/authentication/test/client/index.test.js b/packages/authentication/test/client/index.test.js index 7160715d7a..3504d848cb 100644 --- a/packages/authentication/test/client/index.test.js +++ b/packages/authentication/test/client/index.test.js @@ -76,6 +76,7 @@ const setupTests = initApp => { .then(() => done(new Error('Should never get here'))) .catch(error => { assert.equal(error.message, 'Could not find stored JWT and no authentication type was given'); + assert.equal(error.code, 401); done(); }); });