forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: show string errors. Fixes grafana#15782
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,5 @@ export function getMessageFromError(err: any): string | null { | |
} | ||
} | ||
|
||
return null; | ||
return err; | ||
} |