blob: 53588e4f76e54cce0bd2ddfa8dcbfe15c58abe36 [file] [log] [blame]
Zack Williams477ba092018-10-17 10:50:06 -07001/*
2 Copyright (C) 2018 Open Networking Foundation
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040018#include "error_format.h"
19using grpc::Status;
20using grpc::StatusCode;
21
22
23Status bcm_to_grpc_err(bcmos_errno bcm_err, std::string message) {
24 StatusCode grpc_err = StatusCode::INTERNAL;
25
26 switch (bcm_err) {
27 case BCM_ERR_PARM:
28 grpc_err = StatusCode::INVALID_ARGUMENT;
29 break;
30 case BCM_ERR_RANGE:
31 grpc_err = StatusCode::OUT_OF_RANGE;
32 break;
33 case BCM_ERR_NOT_SUPPORTED:
34 grpc_err = StatusCode::UNIMPLEMENTED;
35 break;
36 case BCM_ERR_NOENT:
37 case BCM_ERR_NODEV:
38 grpc_err = StatusCode::NOT_FOUND;
39 break;
40 case BCM_ERR_TIMEOUT:
41 case BCM_ERR_TOO_LONG:
42 case BCM_ERR_TOO_MANY_REQS:
43 grpc_err = StatusCode::DEADLINE_EXCEEDED;
44 break;
45 case BCM_ERR_ALREADY:
46 grpc_err = StatusCode::ALREADY_EXISTS;
47 break;
48 case BCM_ERR_NO_MORE:
49 case BCM_ERR_INSUFFICIENT_LIST_MEM:
50 grpc_err = StatusCode::RESOURCE_EXHAUSTED;
51 break;
52 }
53
54 message.append(" BCM Error ");
55 message.append(std::to_string(bcm_err));
56
57 return Status(grpc_err, message);
58}
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040059
60std::string grpc_status_code_to_string(StatusCode status_code) {
61 switch (status_code) {
62 case StatusCode::OK:
63 return "StatusCode::OK";
64 case StatusCode::CANCELLED:
65 return "StatusCode::CANCELED";
66 case StatusCode::UNKNOWN:
67 return "StatusCode::UNKNOWN";
68 case StatusCode::INVALID_ARGUMENT:
69 return "StatusCode::INVALID_ARGUMENT";
70 case StatusCode::DEADLINE_EXCEEDED:
71 return "StatusCode::DEADLINE_EXCEEDED";
72 case StatusCode::NOT_FOUND:
73 return "StatusCode::NOT_FOUND";
74 case StatusCode::ALREADY_EXISTS:
75 return "StatusCode::ALREADY_EXISTS";
76 case StatusCode::PERMISSION_DENIED:
77 return "StatusCode::PERMISSION_DENIED";
78 case StatusCode::UNAUTHENTICATED:
79 return "StatusCode::UNAUTHENTICATED";
80 case StatusCode::RESOURCE_EXHAUSTED:
81 return "StatusCode::RESOURCE_EXHAUSTED";
82 case StatusCode::FAILED_PRECONDITION:
83 return "StatusCode::FAILED_PRECONDITION";
84 case StatusCode::ABORTED:
85 return "StatusCode::ABORTED";
86 case StatusCode::OUT_OF_RANGE:
87 return "StatusCode::OUT_OF_RANGE";
88 case StatusCode::INTERNAL:
89 return "StatusCode::INTERNAL";
90 case StatusCode::UNAVAILABLE:
91 return "StatusCode::UNAVAILABLE";
92 case StatusCode::DATA_LOSS:
93 return "StatusCode::DATA_LOSS";
94 case StatusCode::DO_NOT_USE:
95 return "StatusCode::DO_NOT_USE";
96 }
97 return "Unknown GRPC status Code";
98
99}