GRPC C++  1.3.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
status.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPCXX_IMPL_CODEGEN_STATUS_H
35 #define GRPCXX_IMPL_CODEGEN_STATUS_H
36 
39 
40 namespace grpc {
41 
45 class Status {
46  public:
48  Status() : code_(StatusCode::OK) {}
49 
52  : code_(code), error_message_(error_message) {}
53 
57  : code_(code),
58  error_message_(error_message),
59  binary_error_details_(error_details) {}
60 
61  // Pre-defined special status objects.
63  static const Status& OK;
65  static const Status& CANCELLED;
66 
68  StatusCode error_code() const { return code_; }
70  grpc::string error_message() const { return error_message_; }
72  // Usually it contains a serialized google.rpc.Status proto.
73  grpc::string error_details() const { return binary_error_details_; }
74 
76  bool ok() const { return code_ == StatusCode::OK; }
77 
78  private:
79  StatusCode code_;
80  grpc::string error_message_;
81  grpc::string binary_error_details_;
82 };
83 
84 } // namespace grpc
85 
86 #endif // GRPCXX_IMPL_CODEGEN_STATUS_H
grpc::string error_message() const
Return the instance's error message.
Definition: status.h:70
std::string string
Definition: config.h:50
static const Status & CANCELLED
A CANCELLED pre-defined instance.
Definition: status.h:65
Not an error; returned on success.
Definition: status_code_enum.h:41
StatusCode
Definition: status_code_enum.h:39
Status()
Construct an OK instance.
Definition: status.h:48
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:68
grpc::string error_details() const
Return the (binary) error details.
Definition: status.h:73
bool ok() const
Is the status OK?
Definition: status.h:76
Did it work? If it didn't, why?
Definition: status.h:45
Status(StatusCode code, const grpc::string &error_message)
Construct an instance with associated code and error_message.
Definition: status.h:51
static const Status & OK
An OK pre-defined instance.
Definition: status.h:63
Status(StatusCode code, const grpc::string &error_message, const grpc::string &error_details)
Construct an instance with code, error_message and error_details.
Definition: status.h:55