Google APIs Client Library for C++
|
00001 /* 00002 * \copyright Copyright 2013 Google Inc. All Rights Reserved. 00003 * \license @{ 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 * @} 00018 */ 00019 00020 // Author: ewiseblatt@google.com (Eric Wiseblatt) 00021 /* 00022 * @defgroup PlatformLayer Platform Layer - General Programming Support 00023 * 00024 * These are generic utility classes and functions within the Platform Layer. 00025 */ 00026 #ifndef APISERVING_CLIENTS_CPP_UTIL_STATUS_H_ 00027 #define APISERVING_CLIENTS_CPP_UTIL_STATUS_H_ 00028 #include "googleapis/util/status.h" 00029 namespace googleapis { 00030 00031 namespace client { 00032 00033 /* 00034 * Determine status error::Code to use from a standard Posix errno code. 00035 * @ingroup PlatformLayer 00036 * 00037 * This is more a suggestion than a definitive mapping. 00038 * 00039 * @param[in] errno_code A posix errno. 00040 * @return error code to use when creating a status for the Posix error. 00041 */ 00042 util::error::Code ErrnoCodeToStatusEnum(int errno_code); 00043 00044 /* 00045 * Create a status from a standard Posix errno code. 00046 * @ingroup PlatformLayer 00047 * 00048 * @param[in] errno_code A posix errno. 00049 * @param[in] msg A detailed message explanation can be empty to use a generic 00050 * explanation based on the errno_code. 00051 * @return The status returned will be ok for errno_code 0, otherwise, 00052 * it will be some form of failure. 00053 */ 00054 util::Status StatusFromErrno(int errno_code, const StringPiece& msg = ""); 00055 00056 /* 00057 * Determine status error::Code to use from a standard HTTP response status 00058 * code. 00059 * @ingroup PlatformLayer 00060 * 00061 * This is more a suggestion than a definitive mapping. 00062 * 00063 * @param[in] http_code An HTTP response status code. 00064 * @return error code to use when creating a status for the HTTP status code. 00065 */ 00066 util::error::Code HttpCodeToStatusEnum(int http_code); 00067 00068 /* 00069 * Determine the standard HTTP error message for a given code. 00070 * @ingroup PlatformLayer 00071 * 00072 * @param[in] http_code An HTTP response status code. 00073 * @return short capitalized error phrase. 00074 */ 00075 const string HttpCodeToHttpErrorMessage(int http_code); 00076 00077 /* 00078 * Create a status from a standard HTTP response status code. 00079 * @ingroup PlatformLayer 00080 * 00081 * @param[in] http_code An HTTP status response code. 00082 * @param[in] msg A detailed message explanation can be empty to use a generic 00083 * explanation based on the http_code. 00084 * @return The status returned will be ok for 2xx series responses, otherwise, 00085 * it will be some form of failure. 00086 */ 00087 util::Status StatusFromHttp(int http_code, const StringPiece& msg = ""); 00088 00089 /* 00090 * Shorthand notation for creating a status from a standard util::error enum 00091 * The symbol parameter is the symbolic enum name with the util::error 00092 * namespace stripped from it. 00093 */ 00094 #define STATUS_FROM_ENUM(symbol, msg) \ 00095 util::Status(util::error::symbol, msg) 00096 00097 /* 00098 * Creates a standard OK status. 00099 */ 00100 inline util::Status StatusOk() { return util::Status(); } 00101 00102 /* 00103 * Creates a standard ABORTED status. 00104 */ 00105 inline util::Status StatusAborted(const StringPiece& msg) { 00106 return STATUS_FROM_ENUM(ABORTED, msg); 00107 } 00108 00109 /* 00110 * Creates a standard CANCELLED status. 00111 */ 00112 inline util::Status StatusCanceled(const StringPiece& msg) { 00113 return STATUS_FROM_ENUM(CANCELLED, msg); 00114 } 00115 00116 /* 00117 * Creates a standard DATA_LOSS status. 00118 */ 00119 inline util::Status StatusDataLoss(const StringPiece& msg) { 00120 return STATUS_FROM_ENUM(DATA_LOSS, msg); 00121 } 00122 00123 /* 00124 * Creates a standard DEADLINE_EXCEEDED status. 00125 */ 00126 inline util::Status StatusDeadlineExceeded(const StringPiece& msg) { 00127 return STATUS_FROM_ENUM(DEADLINE_EXCEEDED, msg); 00128 } 00129 00130 /* 00131 * Creates a standard INTERNAL status. 00132 */ 00133 inline util::Status StatusInternalError(const StringPiece& msg) { 00134 return STATUS_FROM_ENUM(INTERNAL, msg); 00135 } 00136 00137 /* 00138 * Creates a standard INVALID_ARGUMENT status. 00139 */ 00140 inline util::Status StatusInvalidArgument(const StringPiece& msg) { 00141 return STATUS_FROM_ENUM(INVALID_ARGUMENT, msg); 00142 } 00143 00144 /* 00145 * Creates a standard OUT_OF_RANGE status. 00146 */ 00147 inline util::Status StatusOutOfRange(const StringPiece& msg) { 00148 return STATUS_FROM_ENUM(OUT_OF_RANGE, msg); 00149 } 00150 00151 /* 00152 * Creates a standard PERMISSION_DENIED status. 00153 */ 00154 inline util::Status StatusPermissionDenied(const StringPiece& msg) { 00155 return STATUS_FROM_ENUM(PERMISSION_DENIED, msg); 00156 } 00157 00158 /* 00159 * Creates a standard UNIMPLEMENTED status. 00160 */ 00161 inline util::Status StatusUnimplemented(const StringPiece& msg) { 00162 return STATUS_FROM_ENUM(UNIMPLEMENTED, msg); 00163 } 00164 00165 /* 00166 * Creates a standard UNKNOWN status. 00167 */ 00168 inline util::Status StatusUnknown(const StringPiece& msg) { 00169 return STATUS_FROM_ENUM(UNKNOWN, msg); 00170 } 00171 00172 /* 00173 * Creates a standard RESOURCE_EXHAUSTED status. 00174 */ 00175 inline util::Status StatusResourceExhausted(const StringPiece& msg) { 00176 return STATUS_FROM_ENUM(RESOURCE_EXHAUSTED, msg); 00177 } 00178 00179 /* 00180 * Creates a standard FAILED_PRECONDITION status. 00181 */ 00182 inline util::Status StatusFailedPrecondition(const StringPiece& msg) { 00183 return STATUS_FROM_ENUM(FAILED_PRECONDITION, msg); 00184 } 00185 00186 } // namespace client 00187 00188 } // namespace googleapis 00189 #endif // APISERVING_CLIENTS_CPP_UTIL_STATUS_H_