Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

how to access status code in fail handler #465

Closed
Flow86 opened this issue Sep 11, 2015 · 4 comments
Closed

how to access status code in fail handler #465

Flow86 opened this issue Sep 11, 2015 · 4 comments
Labels

Comments

@Flow86
Copy link

Flow86 commented Sep 11, 2015

Hi,

I havent found out yet how to access the http response code in a client fail handler.

Example: I try to connect to a wrong url:

[connect] Successful connection
[error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)
[fail] WebSocket Connection localhost:8443 - "WebSocket++/0.6.0" /wsbackend/blablubb 404 websocketpp.processor:20 Invalid HTTP status.
[info] asio async_shutdown error: asio.misc:2 (End of file)

ERROR  : 3 1006 Invalid HTTP status. 1006 : websocketpp.processor:20 - Invalid HTTP status.

the last line is the fail handler

std::cerr << "ERROR  : " << connection->get_state() << " "
              << connection->get_local_close_code() << " "
              << connection->get_local_close_reason() << " "
              << connection->get_remote_close_code() << " "
              << connection->get_remote_close_reason() << ": "
              << connection->get_ec() << " - " << connection->get_ec().message() << std::endl;

How do I get the "404" error code in the fail handler, since I dont have access to m_response

@zaphoyd
Copy link
Owner

zaphoyd commented Sep 17, 2015

Looks like this isn't possible right now. I've added some methods to connection that should make it possible:

  • get_status() will retrieve the HTTP response status.
  • get_response() will retrieve the raw response object, which should provide access for any other response related information that isn't more explicitly wrapped by connection.

@Flow86
Copy link
Author

Flow86 commented Sep 18, 2015

get_status() is wrong (. instead of ->),

it has to be

            http::status_code::value get_status() const
            {
                return m_response.get_status_code();
            }

and perhaps it should be named "get_http_status_code"?
And to be complete, we should expose "get_status_msg" too then?

@zaphoyd
Copy link
Owner

zaphoyd commented Sep 19, 2015

Just pushed another update (b6817e4) that fixes these issues, names the methods get_response_code and get_response_msg to be more consistent with the other methods of this sort. Also adds some tests that actually use these methods to make sure they actually work =)

@Flow86
Copy link
Author

Flow86 commented Sep 21, 2015

works thank you.

@Flow86 Flow86 closed this as completed Sep 21, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants