1

I am using Mapbox autofill. When a user types some address that doesn't exist like in the picture. enter image description here

Then he clicks enter to autofill the full address with the suggestion. The suggestion this way is undefined and error will be thrown:

enter image description here

Uncaught (in promise) Error: suggestion is required.

Through debugging I found this is the place where error happens. enter image description here

I would like to handle it so I could provide the user with some toast message/notification asking him to fill whole address. Leaving it just in the console would be ugly.

I know that there are 3 events that come from autobox and can be handled through eventlistener.

None of them is triggered if the aforementioned error is thrown, even when I was expecting that at least on 'suggesterror'.

Any ideas on how I can catch this error? It seems to be visible in console even on the official example as they are not handling it.

Alameyo
  • 79
  • 6

2 Answers2

2

Mapbox dev here - we have made a fix that will be included in the next release (coming soon!) of Search JS that will remove this console error.

If you want to toast/notify the end-user to fill out all fields, I recommend moving that into form pre-submission validation.

EDIT: this issue has been fixed in v1.0.0-beta.14

0

Seems I have found a solution. Still, I think it's not as clean as its global error handler.

window.addEventListener('unhandledrejection', (event) => { });

Also it doesn't prevent printing to console on firefox.

Alameyo
  • 79
  • 6