Closed warren-gallagher closed 2 years ago
1. If a controller invokes a typeorm facility that throws an exception, what happens? Is the exception logged? Is a 500 returned?
By default, all errors which are not caught make the server return a 500 error to the client. If the settings.debug
option is true
, the server returns also the details of the error.
This can be changed with the handleError
method of the AppController
class, where errors can be converted to a special HTTP response if necessary: https://foalts.org/docs/architecture/error-handling/.
By default, all errors which are not caught are also logged in the console. This can be disabled/changed if necessary with the config setting settings.allErrors
and by adding a building a custom logging system in handleError
: https://foalts.org/docs/common/logging-and-debugging#disabling-error-logging.
2\. What is the recommended advice for using Typeorm: 2.1 Use try/catch and log stuff yourself 2.2 Don't bother trying to catch TypeORM errors, just let the framework handle things
IMO, it depends on each case. If this is error that shouldn't happen, I'd leave a 500 error to signal that something went wrong and this wasn't expected. I think it's easier then to fix the application. If it's "common" error, like trying to get details of a "product/user/etc" that doesn't exist (invalid ID), I would catch this kind of errors to return a 404 to the client.
A couple of related questions: