Improve error logging
Closed this issue · 4 comments
When I first visited the /account/billing page which resided under routes/(admin)/account/billing/manage/+page.server.ts and clicked on the "Manage subscription" button, I got an error 500. And the error message displayed was "Unknown error (PCID). If issue persists, please contact us."
This does not help very much and I was not sure, what was wrong. Then I used good old console.log(e) to output the whole error, which looked like this:
StripeInvalidRequestError: You can’t create a portal session in test mode until you save your customer portal settings in test mode at https://dashboard.stripe.com/test/settings/billing/portal. at StripeError.generate (file:///home/jmartsch/htdocs/SchlummerM%C3%A4rchen/schlummermaerchen/node_modules/stripe/esm/Error.js:7:20) at res.toJSON.then.StripeAPIError.message (file:///home/jmartsch/htdocs/SchlummerM%C3%A4rchen/schlummermaerchen/node_modules/stripe/esm/RequestSender.js:102:43) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { type: 'StripeInvalidRequestError', raw: { message: 'You can’t create a portal session in test mode until you save your customer portal settings in test mode at https://dashboard.stripe.com/test/settings/billing/portal.',
I think it would be good to output the error message from raw.message, instead of a generic error.
As I knew where the error came from, I changed the setting in Stripe and it works.
I'm a big believer that you don't show users internal errors like this. There's nothing they can do to fix it, and it will confuse 99% of users.
We could add more error logging like you did (I'd take a PR adding that for true errors that aren't user data errors). But sending dev-messages to users isn't the solution here.
Thinking about this, this would be the right way to resolve:
- Extend the base error, to add a internal_error property
- Log the internal_error in hook, but only internal_error != nil. We don't want to pollute logs with user-errors (input validation, wrong password, etc): https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror
- Add internal_error properties across the codebase where it makes sense. Real unexpected errors. Not input-validation, wrong password, etc.
I think readable and understandable errors are much better than a cryptic error like "500 unkknown error" because the error is known, and could also have different meanings. If a user contacts you (via form or phone) and wants to tell you what happened they only can tell you it said unkown error (PSE), but you as a dev would still not know the real error.
Maybe show someting like this as an error:
An Error occured. If issue persists, please contact us and tell us this error:
and then in small font the error message
You can’t create a portal session in test mode until you save your customer portal settings in test mode at https://dashboard.stripe.com/test/settings/billing/portal.
If the error would be logged or put out in the console, then devs could see whats going on.
I am a webdev (coming from PHP, also have experience in JS, but not in TS), but these are my first steps with Sveltekit and also with Stripe integration, and without the error being shown while in development, I would not have known where or what to fix.
Sure, I am with you if that the log should not be polluted with user errors.
See second message above - I'm suggesting outputting to console. Just not to UI. That would have solved your issue.
I stand by not putting errors that aren't the users fault nor are fixable by the user in the UI.