smooth-code / smooth.js

Code driven CMS powered by GraphQL & React.
MIT License
26 stars 10 forks source link

feat: new onServerError hook triggered on server errors #42

Closed vripoche closed 4 years ago

vripoche commented 5 years ago

Hi,

Due to the unability of add error middleware in onCreateServer hook because the hook call is before SSR middleware, I propose to add a new node hook to manage SSR errors in project plugins: onServerError. It is called on each server error, with error (and other hook parameters as config) in first argument. It also takes the plugin config as a second parameter if it needed.

gregberge commented 5 years ago

Hello @vripoche, what is the exact use-case? You can't do it in the React world?

vripoche commented 5 years ago

Hello @neoziro ,

My use case is to log errors to Sentry through the node module (SSR side): https://www.npmjs.com/package/@sentry/node

I tried to do that in _errror.js or with ErrorBoundaries in _app.js but the module cannot be loaded in browser, and that files are loaded both in SSR and in browser.

If I read the Express documentation I should add an error middleware, and I should add it in onCreateServer hook, but it is not working.

gregberge commented 4 years ago

@vripoche OK I understand the point. I will merge it as soon as I have time.

vripoche commented 4 years ago

Hello @neoziro,

Did you have enough time to review this PR ? ;)

Thanks for your attention.