@ Override public void writeErrorResponse ( HttpCommand command , DehydratedExecutionContext context , CougarException error , boolean traceStarted ) { try { incrementErrorsWritten ( ) ; final HttpServletResponse response = command . getResponse ( ) ; try { long bytesWritten = 0 ; if ( error . getResponseCode ( ) != ResponseCode . CantWriteToSocket ) { ResponseCodeMapper . setResponseStatus ( response , error . getResponseCode ( ) ) ; ByteCountingOutputStream out = null ; try { int jsonErrorCode = mapServerFaultCodeToJsonErrorCode ( error . getServerFaultCode ( ) ) ; JsonRpcError rpcError = new JsonRpcError ( jsonErrorCode , error . getFault ( ) . getErrorCode ( ) , null ) ; JsonRpcErrorResponse jsonRpcErrorResponse = JsonRpcErrorResponse . buildErrorResponse ( null , rpcError ) ; out = new ByteCountingOutputStream ( response . getOutputStream ( ) ) ; mapper . writeValue ( out , jsonRpcErrorResponse ) ; bytesWritten = out . getCount ( ) ; } catch ( IOException ex ) { handleResponseWritingIOException ( ex , error . getClass ( ) ) ; } finally { closeStream ( out ) ; } } else { LOGGER . debug ( "Skipping error handling for a request where the output channel/socket has been prematurely closed" ) ; } logAccess ( command , resolveContextForErrorHandling ( context , command ) , - 1 , bytesWritten , MediaType . APPLICATION_JSON_TYPE , MediaType . APPLICATION_JSON_TYPE , error . getResponseCode ( ) ) ; } finally { command . onComplete ( ) ; } } finally { if ( context != null && traceStarted ) { tracer . end ( context . getRequestUUID ( ) ) ; } } }
Please note this should only be used when the JSON rpc call itself fails - the answer will not contain any mention of the requests that caused the failure nor their ID