GRPC C++  1.10.0
status.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_IMPL_CODEGEN_STATUS_H
20 #define GRPCPP_IMPL_CODEGEN_STATUS_H
21 
24 
25 namespace grpc {
26 
30 class Status {
31  public:
33  Status() : code_(StatusCode::OK) {}
34 
38  : code_(code), error_message_(error_message) {}
39 
45  : code_(code),
46  error_message_(error_message),
47  binary_error_details_(error_details) {}
48 
49  // Pre-defined special status objects.
51  static const Status& OK;
53  static const Status& CANCELLED;
54 
56  StatusCode error_code() const { return code_; }
58  grpc::string error_message() const { return error_message_; }
60  // Usually it contains a serialized google.rpc.Status proto.
61  grpc::string error_details() const { return binary_error_details_; }
62 
64  bool ok() const { return code_ == StatusCode::OK; }
65 
66  // Ignores any errors. This method does nothing except potentially suppress
67  // complaints from any tools that are checking that errors are not dropped on
68  // the floor.
69  void IgnoreError() const {}
70 
71  private:
72  StatusCode code_;
73  grpc::string error_message_;
74  grpc::string binary_error_details_;
75 };
76 
77 } // namespace grpc
78 
79 #endif // GRPCPP_IMPL_CODEGEN_STATUS_H
std::string string
Definition: config.h:35
static const Status & CANCELLED
A CANCELLED pre-defined instance.
Definition: status.h:53
Not an error; returned on success.
Definition: status_code_enum.h:26
StatusCode
Definition: status_code_enum.h:24
grpc::string error_message() const
Return the instance's error message.
Definition: status.h:58
Status()
Construct an OK instance.
Definition: status.h:33
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:56
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
bool ok() const
Is the status OK?
Definition: status.h:64
Did it work? If it didn't, why?
Definition: status.h:30
Status(StatusCode code, const grpc::string &error_message)
Construct an instance with associated code and error_message.
Definition: status.h:37
static const Status & OK
An OK pre-defined instance.
Definition: status.h:51
void IgnoreError() const
Definition: status.h:69
grpc::string error_details() const
Return the (binary) error details.
Definition: status.h:61
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:43