Example #1
0
        private void PublishError(BoltResponseMessageWriter messageWriter, Neo4jError error)
        {
            try
            {
                if (error.Fatal)
                {
                    messageWriter.Write(new FatalFailureMessage(error.Status(), error.Message()));
                }
                else
                {
                    messageWriter.Write(new FailureMessage(error.Status(), error.Message()));
                }
            }
            catch (PackOutputClosedException e)
            {
                // Can't write error to the client, because the connection is closed.
                // Very likely our error is related to the connection being closed.

                // If the error is that the transaction was terminated, then the error is a side-effect of
                // us cleaning up stuff that was running when the client disconnected. Log a warning without
                // stack trace to highlight clients are disconnecting while stuff is running:
                if (_clientMidOpDisconnectErrors.Contains(error.Status()))
                {
                    Log.warn("Client %s disconnected while query was running. Session has been cleaned up. " + "This can be caused by temporary network problems, but if you see this often, " + "ensure your applications are properly waiting for operations to complete before exiting.", e.ClientAddress());
                    return;
                }

                // If the error isn't that the tx was terminated, log it to the console for debugging. It's likely
                // there are other "ok" errors that we can whitelist into the conditional above over time.
                Log.warn("Unable to send error back to the client. " + e.Message, error.Cause());
            }
            catch (Exception t)
            {
                // some unexpected error happened while writing exception back to the client
                // log it together with the original error being suppressed
                t.addSuppressed(error.Cause());
                Log.error("Unable to send error back to the client", t);
            }
        }