Giter Club home page Giter Club logo

Comments (9)

chrislearn avatar chrislearn commented on August 31, 2024

默认情况下 response 确实 status_code = None;
如果你设置过 status_code, 或者有 res.render(StatusError) 则这里的 status_code 应该就不是 None 了.

from salvo.

infdahai avatar infdahai commented on August 31, 2024

这里要返回个默认值吗?

from salvo.

chrislearn avatar chrislearn commented on August 31, 2024

默认值就是none.没啥意义,所以大概做了个判断。

from salvo.

wonktondI avatar wonktondI commented on August 31, 2024

image
Uploading image.png…
在 handler 返回时,res.status_code(StatusCode::CREATED) (or StatusCode::OK );,可以在中间件中获取到 status_code了。
在返回成功时,能默认给一个 res.status_code(StatusCode::OK) 吗?

from salvo.

chrislearn avatar chrislearn commented on August 31, 2024

做了一点修改, 其实现在的 None 就当作 StatusCode::OK. 不过我仍然想明确区分用户有没有显式设置状态码. 所以, 这里的 status_code 类型是 Option<StatusCode>.

from salvo.

infdahai avatar infdahai commented on August 31, 2024

嗯。我觉得这样会好点。

from salvo.

wonktondI avatar wonktondI commented on August 31, 2024

在 handler 里, res.render() 这个方法里,返回成功时,设置一下状态码,这样可行吗?

from salvo.

chrislearn avatar chrislearn commented on August 31, 2024

状态码是会设置的,只是是在所有的handler执行完毕。而log中间件也是handler 所以设置晚于这个handler的执行。

from salvo.

wonktondI avatar wonktondI commented on August 31, 2024

明白了🌹

from salvo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.