Error catching when preloading fails does not work
Hi,
It seems the code to catch missing id on preloading and translate it into a KError
to generate a 404 status does not work (and I actually get a 500 status in this case).
Typically, in the server/controllers/v1/accounts.js
file, there are these lines which, as far as I understood, should translate the missing account into a 404
response from the API:
let account = await Account.find(accountID);
if (!account) {
throw new KError('Bank account not found', 404);
}
It does not seem to work as Account.find
raises its own exception when not finding an accountID
and the if
test is completely ignored then. At least, in my server logs, I have:
[2017-08-06 02:48:36:51] error - helpers | when preloading a bank account: missing
[2017-08-06T14:48:36.520Z] GET /api/v1/accounts/26f74985558c4655a68af8b6e171e819/operations - 500 (8.926 ms)
with no other occurrences of missing
in the code than in the cozy-db
client.