aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/transport/error_utils.c
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-12-13 17:33:51 -0800
committerGravatar Craig Tiller <ctiller@google.com>2017-01-06 14:52:21 -0800
commitdc21a4efb281459b4d3d046cc17ea89e5b56f878 (patch)
treeadc378617d414bc154c19bbe9e94a00fce1bf92c /src/core/lib/transport/error_utils.c
parent732351f8267e51711abd3a390d940c8177871c97 (diff)
Error handling cleanup
Diffstat (limited to 'src/core/lib/transport/error_utils.c')
-rw-r--r--src/core/lib/transport/error_utils.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/src/core/lib/transport/error_utils.c b/src/core/lib/transport/error_utils.c
index 6403cf80d8..da77828d9c 100644
--- a/src/core/lib/transport/error_utils.c
+++ b/src/core/lib/transport/error_utils.c
@@ -32,12 +32,14 @@
*/
#include "src/core/lib/transport/error_utils.h"
+
#include "src/core/lib/iomgr/error_internal.h"
+#include "src/core/lib/transport/status_conversion.h"
-static grpc_error *recursively_find_error_with_status(grpc_error *error,
- intptr_t *status) {
+static grpc_error *recursively_find_error_with_field(grpc_error *error,
+ grpc_error_ints which) {
// If the error itself has a status code, return it.
- if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, status)) {
+ if (grpc_error_get_int(error, which, NULL)) {
return error;
}
if (grpc_error_is_special(error)) return NULL;
@@ -46,32 +48,64 @@ static grpc_error *recursively_find_error_with_status(grpc_error *error,
while (true) {
grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++);
if (child_error == NULL) break;
- grpc_error *result =
- recursively_find_error_with_status(child_error, status);
+ grpc_error *result = recursively_find_error_with_field(child_error, which);
if (result != NULL) return result;
}
return NULL;
}
-void grpc_error_get_status(grpc_error *error, grpc_status_code *code,
- const char **msg) {
- // Populate code.
+void grpc_error_get_status(grpc_error *error, gpr_timespec deadline,
+ grpc_status_code *code, const char **msg,
+ grpc_http2_error_code *http_error) {
// Start with the parent error and recurse through the tree of children
// until we find the first one that has a status code.
- intptr_t status = GRPC_STATUS_UNKNOWN; // Default in case we don't find one.
- grpc_error *found_error = recursively_find_error_with_status(error, &status);
- *code = (grpc_status_code)status;
- // Now populate msg.
+ grpc_error *found_error =
+ recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS);
+ if (found_error == NULL) {
+ /// If no grpc-status exists, retry through the tree to find a http2 error
+ /// code
+ found_error =
+ recursively_find_error_with_field(error, GRPC_ERROR_INT_HTTP2_ERROR);
+ }
+
// If we found an error with a status code above, use that; otherwise,
// fall back to using the parent error.
if (found_error == NULL) found_error = error;
+
+ grpc_status_code status = GRPC_STATUS_UNKNOWN;
+ intptr_t integer;
+ if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) {
+ status = (grpc_status_code)integer;
+ } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR,
+ &integer)) {
+ status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer,
+ deadline);
+ }
+ if (code != NULL) *code = status;
+
+ if (http_error != NULL) {
+ if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) {
+ *http_error = (grpc_http2_error_code)integer;
+ } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS,
+ &integer)) {
+ *http_error = grpc_status_to_http2_error((grpc_status_code)integer);
+ } else {
+ *http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR
+ : GRPC_HTTP2_INTERNAL_ERROR;
+ }
+ }
+
// If the error has a status message, use it. Otherwise, fall back to
// the error description.
- *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE);
- if (*msg == NULL && status != GRPC_STATUS_OK) {
- *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION);
- if (*msg == NULL) *msg = "unknown error"; // Just in case.
+ if (msg != NULL) {
+ *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE);
+ if (*msg == NULL && error != GRPC_ERROR_NONE) {
+ *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION);
+ if (*msg == NULL) *msg = "unknown error"; // Just in case.
+ }
}
+
+ if (found_error == NULL) found_error = error;
}
bool grpc_error_has_clear_grpc_status(grpc_error *error) {