Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Handle error response codes to HTTP requests.#61

Merged
igorpeshansky merged 3 commits intomasterfrom
igorp-handle-http-codes
Feb 26, 2018
Merged

Handle error response codes to HTTP requests.#61
igorpeshansky merged 3 commits intomasterfrom
igorp-handle-http-codes

Conversation

@igorpeshansky
Copy link
Copy Markdown
Contributor

@igorpeshansky igorpeshansky commented Feb 25, 2018

Depends on #59, but will rebase and merge to master once that's in.

Copy link
Copy Markdown
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. However, the watch response in kubernetes.cc (L750) and the oauth response in oauth2.cc (L238) don't have the error handling code.

@igorpeshansky
Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've added the handling in oauth2.cc.
Unfortunately, there doesn't seem to be a way to do this in the watch code (streaming HTTP), as the cpp-netlib library doesn't support that. I'll bring it up with the upstream maintainers.
PTAL.

@igorpeshansky igorpeshansky force-pushed the igorp-handle-http-codes branch from 7bc2c05 to 32e3db1 Compare February 26, 2018 02:11
@igorpeshansky igorpeshansky changed the base branch from igorp-docker-instance-id to master February 26, 2018 02:12
@igorpeshansky
Copy link
Copy Markdown
Contributor Author

Rebased off master.

Copy link
Copy Markdown
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/api_server.cc Outdated
LOG(INFO) << "Metadata request sent successfully";
}
} catch (const boost::system::system_error& e) {
LOG(ERROR) << "Unsuccessful: " << e.what();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Unsuccessful/Metadata request unsuccessful/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/api_server.cc
http::client::response response = client.post(request);
if (status(response) != 200) {
throw boost::system::system_error(
boost::system::errc::make_error_code(boost::system::errc::not_connected),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe not_connected is the best exception to throw here, but if it's just a matter of getting "something" to throw, it's fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that code is never examined.

Comment thread src/api_server.cc Outdated
request << boost::network::header("Authorization", auth_header);
request << boost::network::body(request_body);
http::client::response response = client.post(request);
if (status(response) != 200) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would accept anything in the 2xx range, technically a POST can result in a 201 Created. Applies to other posts as well. I'm sure it's not our contract with the resource metadata api yet, but just something to be mindful of.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/docker.cc Outdated
}
try {
http::local_client::response response = client.get(request);
if (status(response) != 200) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note, I'm fine with just a 200 here as you have it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed for consistency.

Comment thread src/format.cc

namespace {
template<class T>
std::string AsString(T v) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this being used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 32-34 below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my eyes certainly failed me 🤣

@igorpeshansky igorpeshansky force-pushed the igorp-handle-http-codes branch from 03e04f2 to b64acd4 Compare February 26, 2018 06:13
Copy link
Copy Markdown
Contributor Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed feedback. PTAL.

Comment thread src/api_server.cc Outdated
LOG(INFO) << "Metadata request sent successfully";
}
} catch (const boost::system::system_error& e) {
LOG(ERROR) << "Unsuccessful: " << e.what();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/api_server.cc Outdated
request << boost::network::header("Authorization", auth_header);
request << boost::network::body(request_body);
http::client::response response = client.post(request);
if (status(response) != 200) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/api_server.cc
http::client::response response = client.post(request);
if (status(response) != 200) {
throw boost::system::system_error(
boost::system::errc::make_error_code(boost::system::errc::not_connected),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that code is never examined.

Comment thread src/docker.cc Outdated
}
try {
http::local_client::response response = client.get(request);
if (status(response) != 200) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed for consistency.

Comment thread src/format.cc

namespace {
template<class T>
std::string AsString(T v) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 32-34 below.

Copy link
Copy Markdown
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@igorpeshansky igorpeshansky merged commit 5a459be into master Feb 26, 2018
@igorpeshansky igorpeshansky deleted the igorp-handle-http-codes branch March 3, 2018 22:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants