Pnp-modern-search: Error handling in (custom) result templates (v3/v4)

Created on 7 Jun 2021  Â·  5Comments  Â·  Source: microsoft-search/pnp-modern-search

Is your feature request related to a problem? Please describe.
When I'm using the webpart (in this case: v3.16) as an external SP user and searching for people, it is prevented by Sharepoint for some security, authorization or privacy policy reasons.

As a result, an error message is displayed instead of the search results:

Error making HttpClient request in queryable [500] Internal Server Error ::> {"odata.error":{"code":"-1, Microsoft.Office.Server.Search.REST.SearchServiceException","message":{"lang":"en-US","value":"Unknown error."}}}

Even if I switch off "show blank" the error message appears, although I would expect the "no results found" message to be displayed, because _there are no_ results.

Describe the solution you'd like
The "quick 'n dirty" approach: it would be nice if there would be the "no results found" message; or (alternatively) another more human readable error message, because this is what the end user will see.

Describe alternatives you've considered
A more generic way would be if I could do some custom error handling in the custom Handlebars templates. Maybe there is a way I didn't found on my research?

bug enhancement v3 v4

All 5 comments

Makes sense to trap errors in a better UX indeed 🙂

@wobba Is there any work-around for me to show some custom content (e.g. a link) instead of the creepy error message? For example accessing a property in the result template? I tried but I think with an error, it would never come to render the result templates, right?

We need to properly catch the error for you to change to some message. If you see the error in the json if you use the debug template, then you can catch it. If the debug template don't show, then we have to trap errors (which we probably should :).

Unfortunately, the error is thrown before the templates are getting rendered (even when I choose the "debug" template), but I think you know 😉 so there is no chance for me to catch this error. I can only wait (or hope) for a fix/improvement.
2021-06-14 12_45_28-Search – Microsoft​ Edge

I have one last question: will there be a fix for 3.x too or just for 4.x?

@MarcoSimon I'll address this in both versions.

Was this page helpful?
0 / 5 - 0 ratings