blob: 1bc361fd21c0910681da9639438431c1b6469e16 [file] [log] [blame]
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001#include "error_format.h"
2using grpc::Status;
3using grpc::StatusCode;
4
5
6Status bcm_to_grpc_err(bcmos_errno bcm_err, std::string message) {
7 StatusCode grpc_err = StatusCode::INTERNAL;
8
9 switch (bcm_err) {
10 case BCM_ERR_PARM:
11 grpc_err = StatusCode::INVALID_ARGUMENT;
12 break;
13 case BCM_ERR_RANGE:
14 grpc_err = StatusCode::OUT_OF_RANGE;
15 break;
16 case BCM_ERR_NOT_SUPPORTED:
17 grpc_err = StatusCode::UNIMPLEMENTED;
18 break;
19 case BCM_ERR_NOENT:
20 case BCM_ERR_NODEV:
21 grpc_err = StatusCode::NOT_FOUND;
22 break;
23 case BCM_ERR_TIMEOUT:
24 case BCM_ERR_TOO_LONG:
25 case BCM_ERR_TOO_MANY_REQS:
26 grpc_err = StatusCode::DEADLINE_EXCEEDED;
27 break;
28 case BCM_ERR_ALREADY:
29 grpc_err = StatusCode::ALREADY_EXISTS;
30 break;
31 case BCM_ERR_NO_MORE:
32 case BCM_ERR_INSUFFICIENT_LIST_MEM:
33 grpc_err = StatusCode::RESOURCE_EXHAUSTED;
34 break;
35 }
36
37 message.append(" BCM Error ");
38 message.append(std::to_string(bcm_err));
39
40 return Status(grpc_err, message);
41}
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040042
43std::string grpc_status_code_to_string(StatusCode status_code) {
44 switch (status_code) {
45 case StatusCode::OK:
46 return "StatusCode::OK";
47 case StatusCode::CANCELLED:
48 return "StatusCode::CANCELED";
49 case StatusCode::UNKNOWN:
50 return "StatusCode::UNKNOWN";
51 case StatusCode::INVALID_ARGUMENT:
52 return "StatusCode::INVALID_ARGUMENT";
53 case StatusCode::DEADLINE_EXCEEDED:
54 return "StatusCode::DEADLINE_EXCEEDED";
55 case StatusCode::NOT_FOUND:
56 return "StatusCode::NOT_FOUND";
57 case StatusCode::ALREADY_EXISTS:
58 return "StatusCode::ALREADY_EXISTS";
59 case StatusCode::PERMISSION_DENIED:
60 return "StatusCode::PERMISSION_DENIED";
61 case StatusCode::UNAUTHENTICATED:
62 return "StatusCode::UNAUTHENTICATED";
63 case StatusCode::RESOURCE_EXHAUSTED:
64 return "StatusCode::RESOURCE_EXHAUSTED";
65 case StatusCode::FAILED_PRECONDITION:
66 return "StatusCode::FAILED_PRECONDITION";
67 case StatusCode::ABORTED:
68 return "StatusCode::ABORTED";
69 case StatusCode::OUT_OF_RANGE:
70 return "StatusCode::OUT_OF_RANGE";
71 case StatusCode::INTERNAL:
72 return "StatusCode::INTERNAL";
73 case StatusCode::UNAVAILABLE:
74 return "StatusCode::UNAVAILABLE";
75 case StatusCode::DATA_LOSS:
76 return "StatusCode::DATA_LOSS";
77 case StatusCode::DO_NOT_USE:
78 return "StatusCode::DO_NOT_USE";
79 }
80 return "Unknown GRPC status Code";
81
82}