grpc_intercept_errors

The `grpc_intercept_errors` directive enables or disables interception of gRPC error codes by NGINX.

Syntaxgrpc_intercept_errors on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The grpc_intercept_errors directive in NGINX allows you to manage how gRPC services handle errors. When enabled, NGINX captures the gRPC error responses and replaces them with custom responses based on the defined behavior in the configuration. This can be particularly useful for providing more user-friendly error messages or for standardizing the error responses sent to clients.

This directive takes a boolean argument, either 'on' or 'off'. When set to 'on', NGINX will intercept errors from the upstream gRPC service and allow further configuration to define how those errors should be processed or transformed before being returned to the client. For example, you might want to log the error or map certain error codes to more descriptive messages. If set to 'off', NGINX will simply pass through the error code and message from the backend gRPC service without any interception or modification.

The directive can be used in various contexts including http, server, and location, which allows for fine-grained control over error interception behavior on a per-location or per-server basis, enabling different error handling strategies as needed throughout your application.

Config Example

http {
    server {
        location /some-grpc-service {
            grpc_pass grpc://backend_service;
            grpc_intercept_errors on;
        }
    }
}

Ensure that you have proper error handling configured; otherwise, users may receive unexpected default error messages.

Be aware that some gRPC error codes might not translate well into HTTP responses, so configure carefully.

← Back to all directives