Skip to content

Commit

Permalink
utils: show string errors. Fixes grafana#15782
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellee committed Mar 5, 2019
1 parent 989147a commit 8b1e25b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions public/app/core/utils/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { getMessageFromError } from 'app/core/utils/errors';

describe('errors functions', () => {
let message;

describe('when getMessageFromError gets an error string', () => {
beforeEach(() => {
message = getMessageFromError('error string');
});

it('should return the string', () => {
expect(message).toBe('error string');
});
});

describe('when getMessageFromError gets an error object with message field', () => {
beforeEach(() => {
message = getMessageFromError({ message: 'error string' });
});

it('should return the message text', () => {
expect(message).toBe('error string');
});
});

describe('when getMessageFromError gets an error object with data.message field', () => {
beforeEach(() => {
message = getMessageFromError({ data: { message: 'error string' } });
});

it('should return the message text', () => {
expect(message).toBe('error string');
});
});

describe('when getMessageFromError gets an error object with statusText field', () => {
beforeEach(() => {
message = getMessageFromError({ statusText: 'error string' });
});

it('should return the statusText text', () => {
expect(message).toBe('error string');
});
});

describe('when getMessageFromError gets an error object', () => {
beforeEach(() => {
message = getMessageFromError({ customError: 'error string' });
});

it('should return the stringified error', () => {
expect(message).toBe('{"customError":"error string"}');
});
});
});
2 changes: 1 addition & 1 deletion public/app/core/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function getMessageFromError(err: any): string | null {
}
}

return null;
return err;
}

0 comments on commit 8b1e25b

Please sign in to comment.