Repository: auth0/node-auth0 (ts)

Issue:
APIError.message is type String
It appears that the `.message` property on errors APIErrors returned from `signUp` call are of type `String`

![image](https://cloud.githubusercontent.com/assets/5395403/22269858/198db21c-e25b-11e6-9474-2da82023c3c4.png)

is this the desired behavior? It seems a bit odd to include an object in stringified form...

Pull request description:
Update packages and utilize error classes from rest-facade correctly (Fixes #154)
Fixes #154
- Use error classes from rest-facade for consistency
- Fix APIError not being constructed correctly by rest-facade due to missing errorFormatter config
- Fix test case in oauth.tests.js incorrectly using return twice

Patch:
diff --git a/package.json b/package.json
index 7b8bf66e8..43eba39ec 100644
--- a/package.json
+++ b/package.json
@@ -25,8 +25,8 @@
   "dependencies": {
     "bluebird": "^2.10.2",
     "request": "^2.81.0",
-    "rest-facade": "^1.2.7",
-    "url-join": "0.0.1"
+    "rest-facade": "^1.5.0",
+    "url-join": "2.0.2"
   },
   "devDependencies": {
     "chai": "^2.2.0",
diff --git a/src/auth/DatabaseAuthenticator.js b/src/auth/DatabaseAuthenticator.js
index fa7085b2c..77190a5a7 100644
--- a/src/auth/DatabaseAuthenticator.js
+++ b/src/auth/DatabaseAuthenticator.js
@@ -1,6 +1,6 @@
 var extend = require('util')._extend;
 
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var RestClient = require('rest-facade').Client;
 
 
@@ -25,10 +25,17 @@ var DatabaseAuthenticator = function (options, oauth) {
     throw new ArgumentError('The authenticator options must be an object');
   }
 
-  var dbConnectionsUrl = options.baseUrl + '/dbconnections/:type';
+  /**
+   * Options object for the Rest Client instace.
+   *
+   * @type {Object}
+   */
+  var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' }
+  };
 
   this.oauth = oauth;
-  this.dbConnections = new RestClient(dbConnectionsUrl);
+  this.dbConnections = new RestClient(options.baseUrl + '/dbconnections/:type', clientOptions);
   this.clientId = options.clientId;
 };
 
diff --git a/src/auth/OAuthAuthenticator.js b/src/auth/OAuthAuthenticator.js
index 6002da3a9..2acaed3dc 100644
--- a/src/auth/OAuthAuthenticator.js
+++ b/src/auth/OAuthAuthenticator.js
@@ -1,6 +1,6 @@
 var extend = require('util')._extend;
 
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var RestClient = require('rest-facade').Client;
 
 
@@ -25,9 +25,16 @@ var OAuthAuthenticator = function (options) {
     throw new ArgumentError('The authenticator options must be an object');
   }
 
-  var oauthUrl = options.baseUrl + '/oauth/:type';
+  /**
+   * Options object for the Rest Client instace.
+   *
+   * @type {Object}
+   */
+  var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' }
+  };
 
-  this.oauth = new RestClient(oauthUrl);
+  this.oauth = new RestClient(options.baseUrl + '/oauth/:type', clientOptions);
   this.clientId = options.clientId;
   this.clientSecret = options.clientSecret;
 };
diff --git a/src/auth/PasswordlessAuthenticator.js b/src/auth/PasswordlessAuthenticator.js
index bb644f054..260867176 100644
--- a/src/auth/PasswordlessAuthenticator.js
+++ b/src/auth/PasswordlessAuthenticator.js
@@ -1,6 +1,6 @@
 var extend = require('util')._extend;
 
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var RestClient = require('rest-facade').Client;
 
 
@@ -24,10 +24,17 @@ var PasswordlessAuthenticator = function (options, oauth) {
     throw new ArgumentError('The authenticator options must be an object');
   }
 
-  var baseUrl = options.baseUrl + '/passwordless/start';
+  /**
+   * Options object for the Rest Client instace.
+   *
+   * @type {Object}
+   */
+  var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' }
+  };
 
   this.oauth = oauth;
-  this.passwordless = new RestClient(baseUrl);
+  this.passwordless = new RestClient(options.baseUrl + '/passwordless/start', clientOptions);
   this.clientId = options.clientId;
 };
 
diff --git a/src/auth/TokensManager.js b/src/auth/TokensManager.js
index 247e17cb1..5b6afb4e2 100644
--- a/src/auth/TokensManager.js
+++ b/src/auth/TokensManager.js
@@ -1,7 +1,7 @@
 var extend = require('util')._extend;
 var getRequestPromise = require('../utils').getRequestPromise;
 
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
diff --git a/src/auth/UsersManager.js b/src/auth/UsersManager.js
index b5f8d0e1c..6307d1287 100644
--- a/src/auth/UsersManager.js
+++ b/src/auth/UsersManager.js
@@ -1,7 +1,7 @@
 var extend = require('util')._extend;
 var getRequestPromise = require('../utils').getRequestPromise;
 
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
diff --git a/src/auth/index.js b/src/auth/index.js
index 90f1d8b99..e7ea2d7c8 100644
--- a/src/auth/index.js
+++ b/src/auth/index.js
@@ -5,7 +5,7 @@ var util = require('util');
 var pkg = require('../../package.json');
 var utils = require('../utils');
 var jsonToBase64 = utils.jsonToBase64;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 // Authenticators.
 var OAuthAuthenticator = require('./OAuthAuthenticator');
diff --git a/src/exceptions/ApiError.js b/src/exceptions/ApiError.js
deleted file mode 100644
index 3e3561e4e..000000000
--- a/src/exceptions/ApiError.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var util = require('util');
-
-var ApiError = function(statusCode, error, message){
-  this.error = error;
-  this.message = message;
-  this.statusCode = statusCode;
-};
-
-util.inherits(ApiError, Error);
-
-module.exports = ApiError;
diff --git a/src/exceptions/ArgumentError.js b/src/exceptions/ArgumentError.js
deleted file mode 100644
index 0500cbed6..000000000
--- a/src/exceptions/ArgumentError.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var util = require('util');
-
-
-var ArgumentError = function(message){
-  this.message = message;
-};
-
-util.inherits(ArgumentError, Error);
-
-
-module.exports = ArgumentError;
diff --git a/src/exceptions/index.js b/src/exceptions/index.js
deleted file mode 100644
index 1f3fa588d..000000000
--- a/src/exceptions/index.js
+++ /dev/null
@@ -1,4 +0,0 @@
-module.exports = {
-  ApiError: require('./ApiError.js'),
-  ArgumentError: require('./ArgumentError.js')
-};
diff --git a/src/management/BlacklistedTokensManager.js b/src/management/BlacklistedTokensManager.js
index 66eb87175..83d8d4a68 100644
--- a/src/management/BlacklistedTokensManager.js
+++ b/src/management/BlacklistedTokensManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
@@ -33,6 +33,7 @@ var BlacklistedTokensManager = function (options) {
    * @type {Object}
    */
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/ClientGrantsManager.js b/src/management/ClientGrantsManager.js
index 3f1e24f9f..9f74e1882 100644
--- a/src/management/ClientGrantsManager.js
+++ b/src/management/ClientGrantsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
@@ -35,6 +35,7 @@ var ClientGrantsManager = function (options) {
    * @type {Object}
    */
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/ClientsManager.js b/src/management/ClientsManager.js
index 6f68be200..f8c9642f3 100644
--- a/src/management/ClientsManager.js
+++ b/src/management/ClientsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
@@ -38,6 +38,7 @@ var ClientsManager = function (options) {
    * @type {Object}
    */
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/ConnectionsManager.js b/src/management/ConnectionsManager.js
index e60369f2a..fc69f04f2 100644
--- a/src/management/ConnectionsManager.js
+++ b/src/management/ConnectionsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
diff --git a/src/management/DeviceCredentialsManager.js b/src/management/DeviceCredentialsManager.js
index 0e4be883a..aae9025d2 100644
--- a/src/management/DeviceCredentialsManager.js
+++ b/src/management/DeviceCredentialsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
@@ -39,6 +39,7 @@ var DeviceCredentialsManager = function (options) {
    * @type {Object}
    */
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/EmailProviderManager.js b/src/management/EmailProviderManager.js
index 00b638189..33ade9a0c 100644
--- a/src/management/EmailProviderManager.js
+++ b/src/management/EmailProviderManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
@@ -39,6 +39,7 @@ var EmailProviderManager = function (options) {
    * @type {Object}
    */
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/JobsManager.js b/src/management/JobsManager.js
index 0d9346e82..53490fe2a 100644
--- a/src/management/JobsManager.js
+++ b/src/management/JobsManager.js
@@ -4,7 +4,7 @@ var Promise = require('bluebird');
 var fs = require('fs');
 
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
@@ -38,6 +38,7 @@ var JobsManager = function (options){
   }
 
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
@@ -144,7 +145,7 @@ JobsManager.prototype.importUsers = function (data, cb) {
         connection_id: data.connection_id
       }
     }, function (err, res) {
-      
+
 
       // `superagent` uses the error parameter in callback on http errors.
       // the following code is intended to keep that behaviour (https://github.com/visionmedia/superagent/blob/master/lib/node/response.js#L170)
diff --git a/src/management/LogsManager.js b/src/management/LogsManager.js
index 4a6dafc67..0070f4b3e 100644
--- a/src/management/LogsManager.js
+++ b/src/management/LogsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
diff --git a/src/management/ResourceServersManager.js b/src/management/ResourceServersManager.js
index 46eaa16bb..178bbb632 100644
--- a/src/management/ResourceServersManager.js
+++ b/src/management/ResourceServersManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 /**
diff --git a/src/management/RulesManager.js b/src/management/RulesManager.js
index bab370d64..45a2d7052 100644
--- a/src/management/RulesManager.js
+++ b/src/management/RulesManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var utils = require('../utils');
 
 
diff --git a/src/management/StatsManager.js b/src/management/StatsManager.js
index e033954c2..a7aaae0de 100644
--- a/src/management/StatsManager.js
+++ b/src/management/StatsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
@@ -33,6 +33,7 @@ var StatsManager = function (options){
   }
 
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/TenantManager.js b/src/management/TenantManager.js
index 548fc39a7..6a78c4edf 100644
--- a/src/management/TenantManager.js
+++ b/src/management/TenantManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
@@ -33,6 +33,7 @@ var TenantManager = function (options){
   }
 
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/TicketsManager.js b/src/management/TicketsManager.js
index 00cc74950..12bb42b4b 100644
--- a/src/management/TicketsManager.js
+++ b/src/management/TicketsManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
@@ -22,6 +22,7 @@ var TicketsManager = function (options){
   }
 
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/UsersManager.js b/src/management/UsersManager.js
index ea8367bec..a6d1c3d23 100644
--- a/src/management/UsersManager.js
+++ b/src/management/UsersManager.js
@@ -1,5 +1,5 @@
 var RestClient = require('rest-facade').Client;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 /**
@@ -33,6 +33,7 @@ var UsersManager = function (options){
   }
 
   var clientOptions = {
+    errorFormatter: { message: 'message', name: 'error' },
     headers: options.headers,
     query: { repeatParams: false }
   };
diff --git a/src/management/index.js b/src/management/index.js
index a5b382a1f..16eabf460 100644
--- a/src/management/index.js
+++ b/src/management/index.js
@@ -5,7 +5,7 @@ var util = require('util');
 var pkg = require('../../package.json');
 var utils = require('../utils');
 var jsonToBase64 = utils.jsonToBase64;
-var ArgumentError = require('../exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 // Managers.
 var ClientsManager = require('./ClientsManager');


Test patch:
diff --git a/test/auth/authentication-client.tests.js b/test/auth/authentication-client.tests.js
index 2afa96bc6..878e2c22c 100644
--- a/test/auth/authentication-client.tests.js
+++ b/test/auth/authentication-client.tests.js
@@ -1,6 +1,6 @@
 var expect = require('chai').expect;
 
-var ArgumentError = require('../../src/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 var AuthenticationClient = require('../../src/auth');
 var OAuthAuthenticator = require('../../src/auth/OAuthAuthenticator');
diff --git a/test/auth/database-auth.tests.js b/test/auth/database-auth.tests.js
index 57114a640..01a667fca 100644
--- a/test/auth/database-auth.tests.js
+++ b/test/auth/database-auth.tests.js
@@ -8,7 +8,7 @@ var DOMAIN = 'tenant.auth0.com';
 var API_URL = 'https://' + DOMAIN;
 var CLIENT_ID = 'TEST_CLIENT_ID';
 
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var Authenticator = require(SRC_DIR + '/auth/DatabaseAuthenticator');
 var OAuth = require(SRC_DIR + '/auth/OAuthAuthenticator');
 
diff --git a/test/auth/oauth.tests.js b/test/auth/oauth.tests.js
index ecc8ee33c..75b284a44 100644
--- a/test/auth/oauth.tests.js
+++ b/test/auth/oauth.tests.js
@@ -10,7 +10,7 @@ var API_URL = 'https://' + DOMAIN;
 var CLIENT_ID = 'TEST_CLIENT_ID';
 var CLIENT_SECRET = 'TEST_CLIENT_SECRET';
 
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var Authenticator = require(SRC_DIR + '/auth/OAuthAuthenticator');
 
 var validOptions = {
@@ -560,8 +560,7 @@ describe('OAuthAuthenticator', function () {
 
       var request = nock(API_URL)
         .post(path, function (body) {
-          return body.client_id === CLIENT_ID;
-          return body.client_secret === CLIENT_SECRET;
+          return body.client_id === CLIENT_ID && body.client_secret === CLIENT_SECRET;
         })
         .reply(200);
 
diff --git a/test/auth/passwordless.tests.js b/test/auth/passwordless.tests.js
index 9d6eed319..4b69b0574 100644
--- a/test/auth/passwordless.tests.js
+++ b/test/auth/passwordless.tests.js
@@ -8,7 +8,7 @@ var DOMAIN = 'tenant.auth0.com';
 var API_URL = 'https://' + DOMAIN;
 var CLIENT_ID = 'TEST_CLIENT_ID';
 
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var Authenticator = require(SRC_DIR + '/auth/PasswordlessAuthenticator');
 var OAuth = require(SRC_DIR + '/auth/OAuthAuthenticator');
 
diff --git a/test/auth/tokens-manager.tests.js b/test/auth/tokens-manager.tests.js
index 9f1b298a1..f6ad4013d 100644
--- a/test/auth/tokens-manager.tests.js
+++ b/test/auth/tokens-manager.tests.js
@@ -4,7 +4,7 @@ var nock = require('nock');
 var BASE_URL = 'https://tenant.auth0.com';
 
 var Promise = require('bluebird');
-var ArgumentError = require('../../src/exceptions/').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var TokensManager = require('../../src/auth/TokensManager');
 
 
diff --git a/test/auth/user-profile.tests.js b/test/auth/user-profile.tests.js
index 88bce4d58..5297bc891 100644
--- a/test/auth/user-profile.tests.js
+++ b/test/auth/user-profile.tests.js
@@ -8,7 +8,7 @@ var DOMAIN = 'tenant.auth0.com';
 var API_URL = 'https://' + DOMAIN;
 var CLIENT_ID = 'TEST_CLIENT_ID';
 
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var Authenticator = require(SRC_DIR + '/auth/OAuthAuthenticator');
 
 var validOptions = {
diff --git a/test/auth/users-manager.tests.js b/test/auth/users-manager.tests.js
index 4eccaa9b4..59af3137c 100644
--- a/test/auth/users-manager.tests.js
+++ b/test/auth/users-manager.tests.js
@@ -5,7 +5,7 @@ var Promise = require('bluebird');
 var BASE_URL = 'https://tenant.auth0.com';
 var CLIENT_ID = 'TEST_CLIENT_ID';
 
-var ArgumentError = require('../../src/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var UsersManager = require('../../src/auth/UsersManager');
 
 
diff --git a/test/management/blacklisted-tokens.tests.js b/test/management/blacklisted-tokens.tests.js
index bdae9ee92..63835f7bd 100644
--- a/test/management/blacklisted-tokens.tests.js
+++ b/test/management/blacklisted-tokens.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var BlacklistedTokensManager = require(SRC_DIR + '/management/BlacklistedTokensManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('BlacklistedTokensManager', function () {
diff --git a/test/management/client-grants.tests.js b/test/management/client-grants.tests.js
index a66b46797..a31bfabfc 100644
--- a/test/management/client-grants.tests.js
+++ b/test/management/client-grants.tests.js
@@ -6,7 +6,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var ClientGrantsManager = require(SRC_DIR + '/management/ClientGrantsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('ClientGrantsManager', function () {
diff --git a/test/management/client.tests.js b/test/management/client.tests.js
index 6e5cd60b7..f550caf33 100644
--- a/test/management/client.tests.js
+++ b/test/management/client.tests.js
@@ -6,7 +6,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var ClientsManager = require(SRC_DIR + '/management/ClientsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('ClientsManager', function () {
diff --git a/test/management/connections.tests.js b/test/management/connections.tests.js
index 4d3a2c4fe..6a49e870f 100644
--- a/test/management/connections.tests.js
+++ b/test/management/connections.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var ConnectionsManager = require(SRC_DIR + '/management/ConnectionsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('ConnectionsManager', function () {
diff --git a/test/management/device-credentials.tests.js b/test/management/device-credentials.tests.js
index bb13293af..2a02c419e 100644
--- a/test/management/device-credentials.tests.js
+++ b/test/management/device-credentials.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var DeviceCredentialsManager = require(SRC_DIR + '/management/DeviceCredentialsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('DeviceCredentialsManager', function () {
diff --git a/test/management/email-provider.tests.js b/test/management/email-provider.tests.js
index f9bec9d3b..9349b9d49 100644
--- a/test/management/email-provider.tests.js
+++ b/test/management/email-provider.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var EmailProviderManager = require(SRC_DIR + '/management/EmailProviderManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('EmailProviderManager', function () {
diff --git a/test/management/jobs.tests.js b/test/management/jobs.tests.js
index 488edb7f6..eba223bd1 100644
--- a/test/management/jobs.tests.js
+++ b/test/management/jobs.tests.js
@@ -7,7 +7,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var JobsManager = require(SRC_DIR + '/management/JobsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('JobsManager', function () {
diff --git a/test/management/logs.tests.js b/test/management/logs.tests.js
index 4b3ebb9ea..7a1452948 100644
--- a/test/management/logs.tests.js
+++ b/test/management/logs.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var LogsManager = require(SRC_DIR + '/management/LogsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('LogsManager', function () {
diff --git a/test/management/management-client.tests.js b/test/management/management-client.tests.js
index b8eb6ce4e..168eb6bab 100644
--- a/test/management/management-client.tests.js
+++ b/test/management/management-client.tests.js
@@ -2,7 +2,7 @@ var expect = require('chai').expect;
 
 var ManagementClient = require('../../src/management');
 
-var ArgumentError = require('../../src/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 var UsersManager = require('../../src/management/UsersManager');
 var BlacklistedTokensManager = require('../../src/management/BlacklistedTokensManager');
 var ClientsManager = require('../../src/management/ClientsManager');
diff --git a/test/management/resource-servers.tests.js b/test/management/resource-servers.tests.js
index c0e56a8e3..d42fbb073 100644
--- a/test/management/resource-servers.tests.js
+++ b/test/management/resource-servers.tests.js
@@ -6,7 +6,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var ResourceServersManager = require(SRC_DIR + '/management/ResourceServersManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 describe('ResourceServersManager', function () {
 
@@ -563,4 +563,4 @@ describe('ResourceServersManager', function () {
     });
   });
 
-});
\ No newline at end of file
+});
diff --git a/test/management/rules.tests.js b/test/management/rules.tests.js
index a64f1c999..59264b236 100644
--- a/test/management/rules.tests.js
+++ b/test/management/rules.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var RulesManager = require(SRC_DIR + '/management/RulesManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('RulesManager', function () {
diff --git a/test/management/stats.tests.js b/test/management/stats.tests.js
index 0e7d0e049..e2074ab08 100644
--- a/test/management/stats.tests.js
+++ b/test/management/stats.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenant.auth0.com';
 
 var StatsManager = require(SRC_DIR + '/management/StatsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('StatsManager', function () {
diff --git a/test/management/tenant.tests.js b/test/management/tenant.tests.js
index 1b71e254c..365012df6 100644
--- a/test/management/tenant.tests.js
+++ b/test/management/tenant.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenants.auth0.com';
 
 var TenantManager = require(SRC_DIR + '/management/TenantManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('TenantManager', function () {
diff --git a/test/management/tickets.tests.js b/test/management/tickets.tests.js
index 7d682d8c0..904f1183e 100644
--- a/test/management/tickets.tests.js
+++ b/test/management/tickets.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenants.auth0.com';
 
 var TicketsManager = require(SRC_DIR + '/management/TicketsManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('TicketsManager', function () {
diff --git a/test/management/users.tests.js b/test/management/users.tests.js
index 7f039ddc3..9d20dcd7d 100644
--- a/test/management/users.tests.js
+++ b/test/management/users.tests.js
@@ -5,7 +5,7 @@ var SRC_DIR = '../../src';
 var API_URL = 'https://tenants.auth0.com';
 
 var UsersManager = require(SRC_DIR + '/management/UsersManager');
-var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
+var ArgumentError = require('rest-facade').ArgumentError;
 
 
 describe('UsersManager', function () {