internal async Task ProcessHandlerErrorAsync(Exception ex, string method, bool isStreaming, JsonSerializerOptions options) { Status status; if (ex is RpcException rpcException) { // RpcException is thrown by client code to modify the status returned from the server. // Log the status and detail. Don't log the exception to reduce log verbosity. GrpcServerLog.RpcConnectionError(Logger, rpcException.StatusCode, rpcException.Status.Detail); status = rpcException.Status; } else { GrpcServerLog.ErrorExecutingServiceMethod(Logger, method, ex); var message = ErrorMessageHelper.BuildErrorMessage("Exception was thrown by handler.", ex, Options.EnableDetailedErrors); // Note that the exception given to status won't be returned to the client. // It is still useful to set in case an interceptor accesses the status on the server. status = new Status(StatusCode.Unknown, message, ex); } await JsonRequestHelpers.SendErrorResponse(HttpContext.Response, RequestEncoding, status, options); if (isStreaming) { await HttpContext.Response.Body.WriteAsync(GrpcProtocolConstants.StreamingDelimiter); } }
private async Task SendCloseAsync(HubConnectionContext connection, Exception exception) { var closeMessage = CloseMessage.Empty; if (exception != null) { var errorMessage = ErrorMessageHelper.BuildErrorMessage("Connection closed with an error.", exception, _enableDetailedErrors); closeMessage = new CloseMessage(errorMessage); } try { await connection.WriteAsync(closeMessage); } catch (Exception ex) { Log.ErrorSendingClose(_logger, ex); } }
private async Task SendCloseAsync(HubConnectionContext connection, Exception?exception, bool allowReconnect) { var closeMessage = CloseMessage.Empty; if (exception != null) { var errorMessage = ErrorMessageHelper.BuildErrorMessage("Connection closed with an error.", exception, _enableDetailedErrors); closeMessage = new CloseMessage(errorMessage, allowReconnect); } else if (allowReconnect) { closeMessage = new CloseMessage(error: null, allowReconnect); } try { await connection.WriteAsync(closeMessage, ignoreAbort : true); } catch (Exception ex) { Log.ErrorSendingClose(_logger, ex); } }