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)
- [Help] Correctly handle message loop on idle websocket connection HOT 16
- Multiple web socket client issues HOT 18
- `zlib::deflate_stream::write` documentation wall of text HOT 1
- Discarding request body without needing a temporary buffer HOT 6
- Ergonomics of error list in `http::async_read` and `http::async_read_header` HOT 4
- Suggestion: Make incremental HTTP reading as easy as incremental HTTP writing HOT 7
- ecorm's List of Pain Points HOT 14
- multiplexing HOT 6
- p0-.,\ HOT 1
- resolver.async_resolve hang issue HOT 2
- http::async_read hides client disconnection errors HOT 7
- http client tcp ssl stream async_shutdown blocks forever HOT 13
- Double definition of zlib DEF_MEM_LEVEL HOT 2
- Multiple unreachable code warnings if compiling with /W4 in VS2022 HOT 4
- Hi
- Hi,
- Facing error while running advanced_server.cpp file in centos 9. HOT 41
- http_client_sync example hangs on uploading ~2GB multipart data HOT 8
- Memory Leak and Random Closed SSL Websocket HOT 5
- JSON Streaming Client for JSON greater than 8 MB HOT 11
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.