Google Cloud C++ Client  1.32.1
C++ Client Library for Google Cloud Platform
status.cc
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/status.h"
16 #include <sstream>
17 
18 namespace google {
19 namespace cloud {
20 inline namespace GOOGLE_CLOUD_CPP_NS {
21 namespace {
22 std::string StatusWhat(Status const& status) {
23  std::ostringstream os;
24  os << status;
25  return std::move(os).str();
26 }
27 } // namespace
28 
29 std::string StatusCodeToString(StatusCode code) {
30  switch (code) {
31  case StatusCode::kOk:
32  return "OK";
34  return "CANCELLED";
36  return "UNKNOWN";
38  return "INVALID_ARGUMENT";
40  return "DEADLINE_EXCEEDED";
42  return "NOT_FOUND";
44  return "ALREADY_EXISTS";
46  return "PERMISSION_DENIED";
48  return "UNAUTHENTICATED";
50  return "RESOURCE_EXHAUSTED";
52  return "FAILED_PRECONDITION";
54  return "ABORTED";
56  return "OUT_OF_RANGE";
58  return "UNIMPLEMENTED";
60  return "INTERNAL";
62  return "UNAVAILABLE";
64  return "DATA_LOSS";
65  default:
66  return "UNEXPECTED_STATUS_CODE=" + std::to_string(static_cast<int>(code));
67  }
68 }
69 
70 std::ostream& operator<<(std::ostream& os, StatusCode code) {
71  return os << StatusCodeToString(code);
72 }
73 
75  : std::runtime_error(StatusWhat(status)), status_(std::move(status)) {}
76 
77 } // namespace GOOGLE_CLOUD_CPP_NS
78 } // namespace cloud
79 } // namespace google