Map Cronet error code to gRPC error code. (#25880)

reviewable/pr25901/r1
yulin liang 4 years ago committed by GitHub
parent 5e03e95c9b
commit fef6eba151
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      src/core/ext/transport/cronet/transport/cronet_status.cc
  2. 4
      src/core/ext/transport/cronet/transport/cronet_status.h
  3. 12
      src/core/ext/transport/cronet/transport/cronet_transport.cc

@ -491,3 +491,37 @@ const char* cronet_net_error_as_string(cronet_net_error_code net_error) {
}
return "UNAVAILABLE.";
}
grpc_status_code cronet_net_error_to_grpc_error(
cronet_net_error_code net_error) {
switch (net_error) {
case OK:
return GRPC_STATUS_OK;
case CRONET_NET_ERROR_ABORTED:
return GRPC_STATUS_ABORTED;
case CRONET_NET_ERROR_ACCESS_DENIED:
case CRONET_NET_ERROR_NETWORK_ACCESS_DENIED:
return GRPC_STATUS_PERMISSION_DENIED;
case CRONET_NET_ERROR_SSL_CLIENT_AUTH_CERT_NEEDED:
case CRONET_NET_ERROR_PROXY_AUTH_UNSUPPORTED:
case CRONET_NET_ERROR_BAD_SSL_CLIENT_AUTH_CERT:
case CRONET_NET_ERROR_PROXY_AUTH_REQUESTED:
case CRONET_NET_ERROR_SSL_CLIENT_AUTH_PRIVATE_KEY_ACCESS_DENIED:
case CRONET_NET_ERROR_SSL_CLIENT_AUTH_CERT_NO_PRIVATE_KEY:
case CRONET_NET_ERROR_SSL_CLIENT_AUTH_SIGNATURE_FAILED:
case CRONET_NET_ERROR_CLIENT_AUTH_CERT_TYPE_UNSUPPORTED:
case CRONET_NET_ERROR_SSL_CLIENT_AUTH_CERT_BAD_FORMAT:
case CRONET_NET_ERROR_SSL_CLIENT_AUTH_NO_COMMON_ALGORITHMS:
case CRONET_NET_ERROR_CERT_AUTHORITY_INVALID:
case CRONET_NET_ERROR_UNEXPECTED_PROXY_AUTH:
case CRONET_NET_ERROR_MALFORMED_IDENTITY:
case CRONET_NET_ERROR_INVALID_AUTH_CREDENTIALS:
case CRONET_NET_ERROR_UNSUPPORTED_AUTH_SCHEME:
case CRONET_NET_ERROR_MISSING_AUTH_CREDENTIALS:
return GRPC_STATUS_UNAUTHENTICATED;
default:
return GRPC_STATUS_UNAVAILABLE;
}
return GRPC_STATUS_UNAVAILABLE;
}

@ -21,6 +21,8 @@
#include <grpc/impl/codegen/port_platform.h>
#include <grpc/status.h>
enum cronet_net_error_code {
//
// Ranges:
@ -1037,5 +1039,7 @@ enum cronet_net_error_code {
};
const char* cronet_net_error_as_string(cronet_net_error_code net_error);
grpc_status_code cronet_net_error_to_grpc_error(
cronet_net_error_code net_error);
#endif /* GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_STATUS_H */

@ -1321,9 +1321,11 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
if (stream_state->state_op_done[OP_CANCEL_ERROR]) {
error = GRPC_ERROR_REF(stream_state->cancel_error);
} else if (stream_state->state_callback_received[OP_FAILED]) {
grpc_status_code grpc_error_code =
cronet_net_error_to_grpc_error(stream_state->net_error);
const char* desc = cronet_net_error_as_string(stream_state->net_error);
error = make_error_with_desc(GRPC_STATUS_UNAVAILABLE,
stream_state->net_error, desc);
error =
make_error_with_desc(grpc_error_code, stream_state->net_error, desc);
} else if (oas->s->state.rs.trailing_metadata_valid) {
grpc_chttp2_incoming_metadata_buffer_publish(
&oas->s->state.rs.trailing_metadata,
@ -1362,10 +1364,12 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) {
if (stream_op->on_complete) {
const char* error_message =
cronet_net_error_as_string(stream_state->net_error);
grpc_status_code grpc_error_code =
cronet_net_error_to_grpc_error(stream_state->net_error);
grpc_core::ExecCtx::Run(
DEBUG_LOCATION, stream_op->on_complete,
make_error_with_desc(GRPC_STATUS_UNAVAILABLE,
stream_state->net_error, error_message));
make_error_with_desc(grpc_error_code, stream_state->net_error,
error_message));
}
} else {
/* All actions in this stream_op are complete. Call the on_complete

Loading…
Cancel
Save