Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: components/autofill/content/browser/wallet/wallet_client.cc

Issue 522023003: handle more http error codes in wallet response (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/browser/wallet/wallet_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/content/browser/wallet/wallet_client.h" 5 #include "components/autofill/content/browser/wallet/wallet_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 int response_code = source->GetResponseCode(); 571 int response_code = source->GetResponseCode();
572 delegate_->GetMetricLogger().LogWalletResponseCode(response_code); 572 delegate_->GetMetricLogger().LogWalletResponseCode(response_code);
573 573
574 switch (response_code) { 574 switch (response_code) {
575 // HTTP_BAD_REQUEST means the arguments are invalid. No point retrying. 575 // HTTP_BAD_REQUEST means the arguments are invalid. No point retrying.
576 case net::HTTP_BAD_REQUEST: { 576 case net::HTTP_BAD_REQUEST: {
577 request_type_ = NO_REQUEST; 577 request_type_ = NO_REQUEST;
578 HandleWalletError(BAD_REQUEST); 578 HandleWalletError(BAD_REQUEST);
579 return; 579 return;
580 } 580 }
581 // HTTP_OK holds a valid response and HTTP_INTERNAL_SERVER_ERROR holds an 581
582 // error code and message for the user. 582 // Valid response.
583 case net::HTTP_OK: 583 case net::HTTP_OK: {
584 scoped_ptr<base::Value> message_value(base::JSONReader::Read(data));
585 if (message_value.get() &&
586 message_value->IsType(base::Value::TYPE_DICTIONARY)) {
587 response_dict.reset(
588 static_cast<base::DictionaryValue*>(message_value.release()));
589 }
590 break;
591 }
592
593 // Response contains an error to show the user.
594 case net::HTTP_FORBIDDEN:
584 case net::HTTP_INTERNAL_SERVER_ERROR: { 595 case net::HTTP_INTERNAL_SERVER_ERROR: {
585 scoped_ptr<base::Value> message_value(base::JSONReader::Read(data)); 596 scoped_ptr<base::Value> message_value(base::JSONReader::Read(data));
586 if (message_value.get() && 597 if (message_value.get() &&
587 message_value->IsType(base::Value::TYPE_DICTIONARY)) { 598 message_value->IsType(base::Value::TYPE_DICTIONARY)) {
588 response_dict.reset( 599 response_dict.reset(
589 static_cast<base::DictionaryValue*>(message_value.release())); 600 static_cast<base::DictionaryValue*>(message_value.release()));
590 } 601 }
591 if (response_code == net::HTTP_INTERNAL_SERVER_ERROR) {
592 request_type_ = NO_REQUEST;
593 602
594 std::string error_type_string; 603 request_type_ = NO_REQUEST;
595 if (!response_dict->GetString(kErrorTypeKey, &error_type_string)) {
596 HandleWalletError(UNKNOWN_ERROR);
597 return;
598 }
599 WalletClient::ErrorType error_type =
600 StringToErrorType(error_type_string);
601 if (error_type == BUYER_ACCOUNT_ERROR) {
602 // If the error_type is |BUYER_ACCOUNT_ERROR|, then
603 // message_type_for_buyer field contains more specific information
604 // about the error.
605 std::string message_type_for_buyer_string;
606 if (response_dict->GetString(kMessageTypeForBuyerKey,
607 &message_type_for_buyer_string)) {
608 error_type = BuyerErrorStringToErrorType(
609 message_type_for_buyer_string);
610 }
611 }
612 604
613 HandleWalletError(error_type); 605 std::string error_type_string;
606 if (!response_dict->GetString(kErrorTypeKey, &error_type_string)) {
607 HandleWalletError(UNKNOWN_ERROR);
614 return; 608 return;
615 } 609 }
616 break; 610 WalletClient::ErrorType error_type = StringToErrorType(error_type_string);
611 if (error_type == BUYER_ACCOUNT_ERROR) {
612 // If the error_type is |BUYER_ACCOUNT_ERROR|, then
613 // message_type_for_buyer field contains more specific information
614 // about the error.
615 std::string message_type_for_buyer_string;
616 if (response_dict->GetString(kMessageTypeForBuyerKey,
617 &message_type_for_buyer_string)) {
618 error_type =
619 BuyerErrorStringToErrorType(message_type_for_buyer_string);
620 }
621 }
622
623 HandleWalletError(error_type);
624 return;
617 } 625 }
618 626
619 // Anything else is an error. 627 // Handle anything else as a generic error.
620 default: 628 default:
621 request_type_ = NO_REQUEST; 629 request_type_ = NO_REQUEST;
622 HandleWalletError(NETWORK_ERROR); 630 HandleWalletError(NETWORK_ERROR);
623 return; 631 return;
624 } 632 }
625 633
626 RequestType type = request_type_; 634 RequestType type = request_type_;
627 request_type_ = NO_REQUEST; 635 request_type_ = NO_REQUEST;
628 636
629 if (type != ACCEPT_LEGAL_DOCUMENTS && !response_dict) { 637 if (type != ACCEPT_LEGAL_DOCUMENTS && !response_dict) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 NOTREACHED(); 800 NOTREACHED();
793 return AutofillMetrics::UNKNOWN_API_CALL; 801 return AutofillMetrics::UNKNOWN_API_CALL;
794 } 802 }
795 803
796 NOTREACHED(); 804 NOTREACHED();
797 return AutofillMetrics::UNKNOWN_API_CALL; 805 return AutofillMetrics::UNKNOWN_API_CALL;
798 } 806 }
799 807
800 } // namespace wallet 808 } // namespace wallet
801 } // namespace autofill 809 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/browser/wallet/wallet_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698