From eb101f820760b96f35721582d2fceca8fcdaff57 Mon Sep 17 00:00:00 2001 From: Patrick Malouin Date: Fri, 10 Jul 2020 12:50:32 -0400 Subject: [PATCH] fix(migrations): handle 404 error for older installations --- package-lock.json | 2 +- package.json | 2 +- src/auth0/handlers/migrations.js | 9 +++++-- tests/auth0/handlers/migrations.tests.js | 30 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) 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', () => {