uwazi
uwazi copied to clipboard
Error-creating util does not return an instance of Error
Our app/api/utils/Error.js
file, which is usually used as createError
from routes and services (search.js
is one of them on the search
function), does not actually return an instance of Error.
It is creating a new object that contains message, code and, depending on the source, appends the original error to the original
property.
This mostly works. But on the testing environment, this produces an problem. Apparently, jest only prints the error if you throw an instance of Error. If you throw an object, that is not printed. If you intentionally do a fail({ error object })
, it works. But, if you just leave the original throw, it will fail the test but print no result whatsoever.
Maybe it's important to have the createError
process actually create an Error? Still, this produces some ciruclar references if you try to stringify itself with the original
key containing the original error, so it's not as straightforward as just returning an error.
I think we should review our error creation and handling in general. newer versions of jest actually report non-error throws, for this particular issue updating jest i think its enough, we want the update anyway.