blob: 73dd63e7201db5d94bf0c295349abcc0234d7150 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller8a9fd522016-03-25 17:09:29 -07003 * Copyright 2015-2016, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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
Craig Tiller9533d042016-03-25 17:11:06 -070034#include "src/core/lib/transport/chttp2/status_conversion.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035
36int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) {
37 switch (status) {
38 case GRPC_STATUS_OK:
39 return GRPC_CHTTP2_NO_ERROR;
40 case GRPC_STATUS_CANCELLED:
41 return GRPC_CHTTP2_CANCEL;
42 case GRPC_STATUS_RESOURCE_EXHAUSTED:
43 return GRPC_CHTTP2_ENHANCE_YOUR_CALM;
44 case GRPC_STATUS_PERMISSION_DENIED:
45 return GRPC_CHTTP2_INADEQUATE_SECURITY;
46 case GRPC_STATUS_UNAVAILABLE:
47 return GRPC_CHTTP2_REFUSED_STREAM;
48 default:
49 return GRPC_CHTTP2_INTERNAL_ERROR;
50 }
51}
52
53grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
54 grpc_chttp2_error_code error) {
55 switch (error) {
56 case GRPC_CHTTP2_NO_ERROR:
57 /* should never be received */
58 return GRPC_STATUS_INTERNAL;
59 case GRPC_CHTTP2_CANCEL:
60 return GRPC_STATUS_CANCELLED;
61 case GRPC_CHTTP2_ENHANCE_YOUR_CALM:
62 return GRPC_STATUS_RESOURCE_EXHAUSTED;
63 case GRPC_CHTTP2_INADEQUATE_SECURITY:
64 return GRPC_STATUS_PERMISSION_DENIED;
65 case GRPC_CHTTP2_REFUSED_STREAM:
66 return GRPC_STATUS_UNAVAILABLE;
67 default:
68 return GRPC_STATUS_INTERNAL;
69 }
70}
71
72grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) {
73 switch (status) {
74 /* these HTTP2 status codes are called out explicitly in status.proto */
75 case 200:
76 return GRPC_STATUS_OK;
77 case 400:
78 return GRPC_STATUS_INVALID_ARGUMENT;
79 case 401:
80 return GRPC_STATUS_UNAUTHENTICATED;
81 case 403:
82 return GRPC_STATUS_PERMISSION_DENIED;
83 case 404:
84 return GRPC_STATUS_NOT_FOUND;
85 case 409:
86 return GRPC_STATUS_ABORTED;
87 case 412:
88 return GRPC_STATUS_FAILED_PRECONDITION;
89 case 429:
90 return GRPC_STATUS_RESOURCE_EXHAUSTED;
91 case 499:
92 return GRPC_STATUS_CANCELLED;
93 case 500:
94 return GRPC_STATUS_UNKNOWN;
95 case 501:
96 return GRPC_STATUS_UNIMPLEMENTED;
97 case 503:
98 return GRPC_STATUS_UNAVAILABLE;
99 case 504:
100 return GRPC_STATUS_DEADLINE_EXCEEDED;
101 /* everything else is unknown */
102 default:
103 return GRPC_STATUS_UNKNOWN;
104 }
105}
106
107int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) {
108 return 200;
Craig Tiller190d3602015-02-18 09:23:38 -0800109}