Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #101 from pmalouin/fix-migrations-unavailable
Browse files Browse the repository at this point in the history
fix(migrations): handle 404 error for older installations
  • Loading branch information
faroceann authored Jul 10, 2020
2 parents aa8d89e + eb101f8 commit d415656
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 7 additions & 2 deletions src/auth0/handlers/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions tests/auth0/handlers/migrations.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit d415656

Please sign in to comment.