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

Exceptions throw 404 rather than 500 #510

Open
cecilcosta opened this issue Jun 17, 2019 · 1 comment
Open

Exceptions throw 404 rather than 500 #510

cecilcosta opened this issue Jun 17, 2019 · 1 comment

Comments

@cecilcosta
Copy link

node.js version: v12.4.0

npm/yarn and version: npm 6.9.0

koa-router version: 3.2.0

koa version: 2.7.0

Code sample:

module.exports.mycall = async (ctx, next) => {
  const object = await ObjectFinder.find(ctx.request.body.id); // this object doesn't exits and an exception is thrown.
  object.date = new Date();
  await object.save()
  ctx.status = 204
};

Expected Behavior:

As there was an exception the response code should be 500

Actual Behavior:

Got a 404, which makes no sense.

Additional steps, HTTP request details, or to reproduce the behavior or a test case:

@Andrew-Nedelenko
Copy link

Andrew-Nedelenko commented Jul 18, 2019

I have similar problem with koa-router (v. 7.4), koa(2.7) i am working with nodemailer, and catching 404 error before like mail sended for user, but want send 200 status after sending mail

`const feedback = async (ctx) => {
const {
company, username, phone, email,
} = ctx.request.body;

// here get 404, but if written ctx.status = 200; it is ok, but not sense

const mailer = async () => {
const transporter = await nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: mailuser,
pass: mailpass,
},
});

const output = `
      <p>company: ${company}</p>
      <p>username: ${username}</p>
      <p>phone: ${phone}</p>
      <p>E-mail: ${email}</p>
`;
const info = await transporter.sendMail({
  from: username,
  to: email,
  subject: email,
  html: output,
});

console.log(info.messageId);
return new Promise((res, rej) => {
if (info.messageId.length > 0) {
res();
return info;
}
rej();
return 0;
});
};

mailer().then(() => {
console.log('where is my OK status ??');
ctx.body = {
status: 200,
msg: 'ok',
};
});
};`

Log in my console

POST /sendfeed - 38ms - 404 - hostOrigin -> undefined userAgent -> PostmanRuntime/7.15.2
cookies: no cookies
9330e33a-8c8e-e962-1bfc-fd4dfd93ce8f@my-pc
where is my OK status ??

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

2 participants