diff --git a/package-lock.json b/package-lock.json index 561b525..e238021 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "4.1.1", + "version": "4.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 345400c..f500ced 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "4.1.2", + "version": "4.1.3", "description": "Supporting tools for the Source Control extensions", "main": "lib/index.js", "scripts": { diff --git a/src/auth0/handlers/migrations.js b/src/auth0/handlers/migrations.js index f1d6872..64b862e 100644 --- a/src/auth0/handlers/migrations.js +++ b/src/auth0/handlers/migrations.js @@ -16,8 +16,13 @@ export default class MigrationsHandler extends DefaultHandler { } async getType() { - const migrations = await this.client.migrations.getMigrations(); - return migrations.flags; + try { + const migrations = await this.client.migrations.getMigrations(); + return migrations.flags; + } catch (err) { + if (err.statusCode === 404) return {}; + throw err; + } } // Run at the end since switching a flag will depend on other applying other changes diff --git a/tests/auth0/handlers/migrations.tests.js b/tests/auth0/handlers/migrations.tests.js index 04ba1c4..da43186 100644 --- a/tests/auth0/handlers/migrations.tests.js +++ b/tests/auth0/handlers/migrations.tests.js @@ -28,6 +28,36 @@ describe('#migrations handler', () => { migration_flag: true }); }); + + it('should support when endpoint does not exist (older installations)', async () => { + const client = { + migrations: { + getMigrations: () => { + const err = new Error('Not Found'); + err.name = 'Not Found'; + err.statusCode = 404; + err.requestInfo = { + method: 'get', + url: 'https://example.auth0.com/api/v2/migrations' + }; + err.originalError = new Error('Not Found'); + err.originalError.status = 404; + err.originalError.response = { + body: { + statusCode: 404, + error: 'Not Found', + message: 'Not Found' + } + }; + return Promise.reject(err); + } + } + }; + + const handler = new migrations({ client }); + const data = await handler.getType(); + expect(data).to.deep.equal({}); + }); }); describe('#migrations process', () => {