Comments (6)
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.
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.
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.
Thanks. That must be relatively new, I don't recall seeing beast::http::parse_error::bad_method anywhere.
from beast.
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.
There's a Gitter chat room for Beast available now:
from beast.
Related Issues (20)
- body_limit exceeded error using coro server example HOT 4
- support SSLKEYLOGFILE env var for wireshark HOT 3
- Test Matrix needs work
- Issue trying to read an "endless" chunked stream HOT 3
- How to establish mapping between C++ classes and database tables using Boost Beast. HOT 3
- Any possibility to make dependency on Boost not required(like ASIO does)? HOT 2
- Chat-Multi Code of Boost Beast is crashing when made some changes. HOT 5
- Question about field used hash function HOT 6
- Web link is broken HOT 1
- Websocket Async Client as a DLL HOT 1
- CI should build documentation on Windows platform
- Beast Server Exits for reasons that Client is disconnecting? HOT 2
- Any benefit to multiple sockets between a server and a single client instance using Boost Beast? HOT 4
- Using a minimal executor causes compile errors with beast::websocket HOT 3
- How to check whether there is any available data on the stream HOT 4
- [HELP] Server heartbeat and response HOT 2
- Limitation of `websocket::stream::accept(...)` and `websocket::stream::async_accept(...)`. HOT 3
- Session communication without Mutex? HOT 4
- The beast Server Exits frequently HOT 3
- Is it possible to serialize the body directly to file from a request_parser<empty_body> HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beast.