mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 01:16:43 +00:00
Merge pull request #1862 from balena-io/fix-balenaexpiredtoken-handling
Fix handling of BalenaExpiredToken error
This commit is contained in:
commit
683037cd2f
@ -135,10 +135,10 @@ const messages: {
|
||||
};
|
||||
|
||||
const EXPECTED_ERROR_REGEXES = [
|
||||
/^BalenaAmbiguousApplication:/, // balena-sdk
|
||||
/^BalenaApplicationNotFound:/, // balena-sdk
|
||||
/^BalenaDeviceNotFound:/, // balena-sdk
|
||||
/^BalenaExpiredToken:/, // balena-sdk
|
||||
/^BalenaAmbiguousApplication/, // balena-sdk
|
||||
/^BalenaApplicationNotFound/, // balena-sdk
|
||||
/^BalenaDeviceNotFound/, // balena-sdk
|
||||
/^BalenaExpiredToken/, // balena-sdk
|
||||
/^Missing \w+$/, // Capitano, oclif parser: RequiredArgsError, RequiredFlagError
|
||||
/^Unexpected argument/, // oclif parser: UnexpectedArgsError
|
||||
/to be one of/, // oclif parser: FlagInvalidOptionError, ArgInvalidOptionError
|
||||
@ -172,7 +172,8 @@ export async function handleError(error: any) {
|
||||
// Expected?
|
||||
const isExpectedError =
|
||||
error instanceof ExpectedError ||
|
||||
EXPECTED_ERROR_REGEXES.some(re => re.test(message[0]));
|
||||
EXPECTED_ERROR_REGEXES.some(re => re.test(message[0])) ||
|
||||
EXPECTED_ERROR_REGEXES.some(re => re.test((error as any).code));
|
||||
|
||||
// Output/report error
|
||||
if (isExpectedError) {
|
||||
|
@ -15,6 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
BalenaAmbiguousApplication,
|
||||
BalenaApplicationNotFound,
|
||||
BalenaDeviceNotFound,
|
||||
BalenaExpiredToken,
|
||||
} from 'balena-errors';
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import ErrorsModule from '../build/errors';
|
||||
@ -124,10 +130,6 @@ describe('handleError() function', () => {
|
||||
});
|
||||
|
||||
const messagesToMatch = [
|
||||
'BalenaAmbiguousApplication:',
|
||||
'BalenaApplicationNotFound:',
|
||||
'BalenaDeviceNotFound:',
|
||||
'BalenaExpiredToken:',
|
||||
'Missing argument',
|
||||
'Missing arguments',
|
||||
'Unexpected argument',
|
||||
@ -149,6 +151,25 @@ describe('handleError() function', () => {
|
||||
expect(processExit.notCalled).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
const typedErrorsToMatch = [
|
||||
new BalenaAmbiguousApplication('test'),
|
||||
new BalenaApplicationNotFound('test'),
|
||||
new BalenaDeviceNotFound('test'),
|
||||
new BalenaExpiredToken('test'),
|
||||
];
|
||||
|
||||
typedErrorsToMatch.forEach(typedError => {
|
||||
it(`should treat typedError ${typedError.name} as expected`, async () => {
|
||||
await ErrorsModule.handleError(typedError);
|
||||
|
||||
expect(printExpectedErrorMessage.calledOnce).to.be.true;
|
||||
|
||||
expect(printErrorMessage.notCalled).to.be.true;
|
||||
expect(captureException.notCalled).to.be.true;
|
||||
expect(processExit.notCalled).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('printErrorMessage() function', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user