Skip to content

Commit

Permalink
[Enterprise Search] Minor flashAPIMessages update (#77570)
Browse files Browse the repository at this point in the history
* Fix missing export 🤦‍♀️

* Add fallback for http errors without an errors array

- all http error messages should still be expected to contain a message key, so should be a reliable fallback
  • Loading branch information
Constance authored Sep 16, 2020
1 parent 5f34d74 commit c84c347
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ describe('flashAPIErrors', () => {
]);
});

it('falls back to the basic message for http responses without an errors array', () => {
flashAPIErrors({
body: {
statusCode: 404,
error: 'Not Found',
message: 'Not Found',
},
} as any);

expect(FlashMessagesLogic.actions.setFlashMessages).toHaveBeenCalledWith([
{ type: 'error', message: 'Not Found' },
]);
});

it('displays a generic error message and re-throws non-API errors', () => {
try {
flashAPIErrors(Error('whatever') as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const flashAPIErrors = (

const errorFlashMessages: IFlashMessage[] = Array.isArray(error?.body?.attributes?.errors)
? error.body!.attributes.errors.map((message) => ({ type: 'error', message }))
: [{ type: 'error', message: defaultErrorMessage }];
: [{ type: 'error', message: error?.body?.message || defaultErrorMessage }];

if (isQueued) {
FlashMessagesLogic.actions.setQueuedMessages(errorFlashMessages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export {
IFlashMessagesActions,
} from './flash_messages_logic';
export { FlashMessagesProvider } from './flash_messages_provider';
export { flashAPIErrors } from './handle_api_errors';

0 comments on commit c84c347

Please sign in to comment.