Git Product home page Git Product logo

Comments (6)

vinniefalco avatar vinniefalco commented on May 2, 2024

I believe you get the error_code out of the system_error and when you make the comparison using error_code, the implementation of error_code checks to see that the error_category associated with the error_code is the same as the error_category associated with the enum. Thats what user defined make_error_code is for, so the implementation of error_code can make the comparison. I believe it is okay for enum values from different error categories to overlap. See:
https://github.com/vinniefalco/Beast/blob/master/include/beast/websocket/impl/error.ipp#L16

Now I could be wrong about this, because the whole error_code and system_error thing is highly confusing and not particularly well explained.

Note that for HTTP, only basic_parser_v1 throws custom error codes, the rest will be the errors thrown by asio. http::write and http::async_write will return boost::asio::error::eof if the message indicates that the connection should be closed afterwards. I might change that.

from beast.

bitbugprime avatar bitbugprime commented on May 2, 2024

I've tested my server with junk input and it throws exceptions like "invalid method" (at least that's what an older version of beast did), which definitely aren't boost::asio::error::??? errors, but I can't figure out what error code namespace/name I should be checking for in my boost::system::system_error catch() block. I test for error::eof and error::operation_aborted, for example.

from beast.

vinniefalco avatar vinniefalco commented on May 2, 2024

This should work:

try
{
    ...
}
catch(boost::system::system_error const& se)
{
    if(se.code() == beast::http::parse_error::bad_method)
        std::cerr << "You got a bad method!\n";
    else if(se.code() == boost::asio::error::eof)
        std::cerr << "End of file reached\n";
    else
        std::cerr << "Some other problem\n";
}

Parse error codes are here:
https://github.com/vinniefalco/Beast/blob/master/include/beast/http/parse_error.hpp#L16

from beast.

bitbugprime avatar bitbugprime commented on May 2, 2024

Thanks. That must be relatively new, I don't recall seeing beast::http::parse_error::bad_method anywhere.

from beast.

vinniefalco avatar vinniefalco commented on May 2, 2024

Ah yes, you're right about that. When Beast was using the nodejs http-parser, it had an error_category that pulled its strings from there:
https://github.com/vinniefalco/Beast/blob/4cfa1d5cd34533caf4930455c6d3817b3bd00e89/include/beast/http/detail/error.hpp#L28

from beast.

vinniefalco avatar vinniefalco commented on May 2, 2024

There's a Gitter chat room for Beast available now:

Join the chat at https://gitter.im/vinniefalco/Beast

from beast.

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.