Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot catch a NoRowsDeletedError or NoRowsUpdatedError #2089

Open
newza-fullmetal opened this issue Oct 27, 2020 · 0 comments
Open

Cannot catch a NoRowsDeletedError or NoRowsUpdatedError #2089

newza-fullmetal opened this issue Oct 27, 2020 · 0 comments

Comments

@newza-fullmetal
Copy link

Hi everyone.

I am struggling to handle error with bookshelf.
I have a controller wich handle the CRUD like this for the GET :

req.models[model].findById(req.params.id)
        .then(user => {
            res.status(200).send(user);
        }).catch(req.models[model].NotFoundError, () => {
            throw new ApiError("NOT_FOUND", `No ${model} found for id ${req.params.id}.`, 404);
        }).catch(err => {
            next(err)
        });

It works perfectly fine.

But for the deletion or update:

req.models[model].delete(req.params.id)
        .then(() => {
            return res.status(204).send();
        })
        .catch(req.models[model].NoRowsDeletedError, () => {
            throw new ApiError("NOT_FOUND", `No ${model} found for id ${req.params.id}.`, 404);
        })

It is not working at all. It is specified in the doc that if no ID exist for a deletion it should return a 'NoRowsDeletedError' here (since the 0.13, and I am in 1.2)

Instead Booshelf make the lib create-error in crash with this message:
Cannot set property 'message' of undefined

because I think the error from Bookshelf is not in a good format
[Arguments] { '0': 'No Rows Deleted' }

I do not know what to do or if I am doing something wrong.

Thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant