Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 1 | /* |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 3 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 7 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 9 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 16 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 17 | #include "error_format.h" |
| 18 | using grpc::Status; |
| 19 | using grpc::StatusCode; |
| 20 | |
| 21 | |
| 22 | Status bcm_to_grpc_err(bcmos_errno bcm_err, std::string message) { |
| 23 | StatusCode grpc_err = StatusCode::INTERNAL; |
| 24 | |
| 25 | switch (bcm_err) { |
| 26 | case BCM_ERR_PARM: |
| 27 | grpc_err = StatusCode::INVALID_ARGUMENT; |
| 28 | break; |
| 29 | case BCM_ERR_RANGE: |
| 30 | grpc_err = StatusCode::OUT_OF_RANGE; |
| 31 | break; |
| 32 | case BCM_ERR_NOT_SUPPORTED: |
| 33 | grpc_err = StatusCode::UNIMPLEMENTED; |
| 34 | break; |
| 35 | case BCM_ERR_NOENT: |
| 36 | case BCM_ERR_NODEV: |
| 37 | grpc_err = StatusCode::NOT_FOUND; |
| 38 | break; |
| 39 | case BCM_ERR_TIMEOUT: |
| 40 | case BCM_ERR_TOO_LONG: |
| 41 | case BCM_ERR_TOO_MANY_REQS: |
| 42 | grpc_err = StatusCode::DEADLINE_EXCEEDED; |
| 43 | break; |
| 44 | case BCM_ERR_ALREADY: |
| 45 | grpc_err = StatusCode::ALREADY_EXISTS; |
| 46 | break; |
| 47 | case BCM_ERR_NO_MORE: |
| 48 | case BCM_ERR_INSUFFICIENT_LIST_MEM: |
| 49 | grpc_err = StatusCode::RESOURCE_EXHAUSTED; |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | message.append(" BCM Error "); |
| 54 | message.append(std::to_string(bcm_err)); |
| 55 | |
| 56 | return Status(grpc_err, message); |
| 57 | } |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 58 | |
| 59 | std::string grpc_status_code_to_string(StatusCode status_code) { |
| 60 | switch (status_code) { |
| 61 | case StatusCode::OK: |
| 62 | return "StatusCode::OK"; |
| 63 | case StatusCode::CANCELLED: |
| 64 | return "StatusCode::CANCELED"; |
| 65 | case StatusCode::UNKNOWN: |
| 66 | return "StatusCode::UNKNOWN"; |
| 67 | case StatusCode::INVALID_ARGUMENT: |
| 68 | return "StatusCode::INVALID_ARGUMENT"; |
| 69 | case StatusCode::DEADLINE_EXCEEDED: |
| 70 | return "StatusCode::DEADLINE_EXCEEDED"; |
| 71 | case StatusCode::NOT_FOUND: |
| 72 | return "StatusCode::NOT_FOUND"; |
| 73 | case StatusCode::ALREADY_EXISTS: |
| 74 | return "StatusCode::ALREADY_EXISTS"; |
| 75 | case StatusCode::PERMISSION_DENIED: |
| 76 | return "StatusCode::PERMISSION_DENIED"; |
| 77 | case StatusCode::UNAUTHENTICATED: |
| 78 | return "StatusCode::UNAUTHENTICATED"; |
| 79 | case StatusCode::RESOURCE_EXHAUSTED: |
| 80 | return "StatusCode::RESOURCE_EXHAUSTED"; |
| 81 | case StatusCode::FAILED_PRECONDITION: |
| 82 | return "StatusCode::FAILED_PRECONDITION"; |
| 83 | case StatusCode::ABORTED: |
| 84 | return "StatusCode::ABORTED"; |
| 85 | case StatusCode::OUT_OF_RANGE: |
| 86 | return "StatusCode::OUT_OF_RANGE"; |
| 87 | case StatusCode::INTERNAL: |
| 88 | return "StatusCode::INTERNAL"; |
| 89 | case StatusCode::UNAVAILABLE: |
| 90 | return "StatusCode::UNAVAILABLE"; |
| 91 | case StatusCode::DATA_LOSS: |
| 92 | return "StatusCode::DATA_LOSS"; |
| 93 | case StatusCode::DO_NOT_USE: |
| 94 | return "StatusCode::DO_NOT_USE"; |
| 95 | } |
| 96 | return "Unknown GRPC status Code"; |
| 97 | |
| 98 | } |