question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raising error in post save middleware

See original GitHub issue

Just looking for guidance on how to raise errors from a post handler. For example,

doc.post('save', function(d){
  // something goes wrong here!
  throw new Error('whatever');
});

Is that the preferred method in there, since there’s no next or done?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dcharbonniercommented, Mar 24, 2017

it was announced for 4.x but I don;t see the doc

0reactions
pvencillcommented, Jun 6, 2014

Ok, that makes sense to me, thanks. On Jun 6, 2014 1:38 PM, “Valeri Karpov” notifications@github.com wrote:

Well, if you need to retry, that’s doable within the post save hook itself. The tricky bit is communicating the error. If you want a generic post save hook error handler for a particular model, you can tell your model to listen for a certain event, e.g. postSaveError, and have your post save hook emit postSaveError with the associated err object when an error occurs.

— Reply to this email directly or view it on GitHub https://github.com/LearnBoost/mongoose/issues/2124#issuecomment-45363844 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose - How can I throw more than one error in pre (save ...
I have some pre save and update hooks in a model and I need to show all the errors of validations at same...
Read more >
Mongoose v6.8.1: Middleware
Middleware (also called pre and post hooks) are functions which are passed control during execution of asynchronous functions. Middleware is specified on ...
Read more >
Using MongoDB with Mongoose — Pre Middleware Errors ...
We have to define middleware before we create the model with the schema for it to fire. run(); We created the schema and...
Read more >
A Guide to Error Handling in Express.js | Scout APM Blog
First, we create one parent error class (CharacterCountExceeded) for all errors that involve an exceeded character count. The constructor for ...
Read more >
Handling errors in Mongoose/Express to display in React | by JB
1. Set up error handling middleware · Email or username is already taken. · Username contains characters that aren't letters/numbers. · Password ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found