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
Res.status returns 404 when using promises in routes #20
Comments
Hey, Thanks for your question. If you didn't mind providing a code snippet that would be a huge help. require('isomorphic-fetch')
app.get('/home', (ctx) => {
return fetch('http://google.ca')
.then(response => response.text())
.then(html => {
ctx.res.body = html
})
}) |
@DylanPiercey I have something like that too. At what point is the |
If the body is non empty the status will default to 200. You can also manually set |
@DylanPiercey So the promise needs to be returned for it to properly resolve. |
@imolorhe that is correct, otherwise Rill has no idea when the promise finishes. |
@DylanPiercey Okay so what exactly determines the value of |
ctx.res.status will only automatically set if there is a ctx.res.body, if there is a ctx.res.body it will default to 200. Otherwise it is 404 unless explicitly set by the user. |
@DylanPiercey Thanks! I know it's probably too much to ask, but what is the promise-based equivalent of this snippet: app.use(async (ctx, next)=> {
try {
await next()
} catch (error) {
// Catch errors later on in the stack.
log.error('server error', err)
}
}) |
@imolorhe no problem - app.use((ctx, next) => {
return next().catch((err) => {
log.error('server error', err)
})
}) |
@imolorhe i'm going to close this for now. Hit me up on gitter if you have any other questions regarding this or promises 😄. |
@DylanPiercey Okay |
Hello,
The response object returns a 404 whenever I use promises with the routes. When I remove the promise, the response is resolved normally. The examples on the site are done with async/await, so I think that is likely the issue. Is there any example using regular promises?
The text was updated successfully, but these errors were encountered: