Search in sources :

Example 1 with ErrorType

use of com.netflix.zuul.exception.ErrorType in project zuul by Netflix.

the class BasicNettyOrigin method recordFinalError.

@Override
public void recordFinalError(HttpRequestMessage requestMsg, Throwable throwable) {
    if (throwable == null) {
        return;
    }
    final SessionContext zuulCtx = requestMsg.getContext();
    // Choose StatusCategory based on the ErrorType.
    final ErrorType et = requestAttemptFactory.mapNettyToOutboundErrorType(throwable);
    final StatusCategory nfs = et.getStatusCategory();
    zuulCtx.put(CommonContextKeys.STATUS_CATGEORY, nfs);
    zuulCtx.put(CommonContextKeys.ORIGIN_STATUS_CATEGORY, nfs);
    zuulCtx.setError(throwable);
}
Also used : StatusCategory(com.netflix.zuul.stats.status.StatusCategory) ErrorType(com.netflix.zuul.exception.ErrorType) SessionContext(com.netflix.zuul.context.SessionContext)

Example 2 with ErrorType

use of com.netflix.zuul.exception.ErrorType in project zuul by Netflix.

the class ProxyEndpoint method processErrorFromOrigin.

private void processErrorFromOrigin(final Throwable ex, final Channel origCh) {
    try {
        final SessionContext zuulCtx = context;
        final ErrorType err = requestAttemptFactory.mapNettyToOutboundErrorType(ex);
        // Be cautious about how much we log about errors from origins, as it can have perf implications at high rps.
        if (zuulCtx.isInBrownoutMode()) {
            // Don't include the stacktrace or the channel info.
            LOG.warn(err.getStatusCategory().name() + ", origin = " + origin.getName() + ": " + String.valueOf(ex));
        } else {
            final String origChInfo = (origCh != null) ? ChannelUtils.channelInfoForLogging(origCh) : "";
            if (LOG.isInfoEnabled()) {
                // Include the stacktrace.
                LOG.warn(err.getStatusCategory().name() + ", origin = " + origin.getName() + ", origin channel info = " + origChInfo, ex);
            } else {
                LOG.warn(err.getStatusCategory().name() + ", origin = " + origin.getName() + ", " + String.valueOf(ex) + ", origin channel info = " + origChInfo);
            }
        }
        // Update the NIWS stat.
        if (currentRequestStat != null) {
            currentRequestStat.failAndSetErrorCode(err);
        }
        // Update RequestAttempt info.
        if (currentRequestAttempt != null) {
            currentRequestAttempt.complete(-1, currentRequestStat.duration(), ex);
        }
        postErrorProcessing(ex, zuulCtx, err, chosenServer.get(), attemptNum);
        final ClientException niwsEx = new ClientException(ClientException.ErrorType.valueOf(err.getClientErrorType().name()));
        if (chosenServer.get() != DiscoveryResult.EMPTY) {
            origin.onRequestExceptionWithServer(zuulRequest, chosenServer.get(), attemptNum, niwsEx);
        }
        if ((isBelowRetryLimit()) && (isRetryable(err))) {
            // retry request with different origin
            passport.add(ORIGIN_RETRY_START);
            origin.adjustRetryPolicyIfNeeded(zuulRequest);
            proxyRequestToOrigin();
        } else {
            // Record the exception in context. An error filter should later run which can translate this into an
            // app-specific error response if needed.
            zuulCtx.setError(ex);
            zuulCtx.setShouldSendErrorResponse(true);
            StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulCtx, err.getStatusCategory());
            origin.recordFinalError(zuulRequest, ex);
            origin.onRequestExecutionFailed(zuulRequest, chosenServer.get(), attemptNum - 1, niwsEx);
            // Send error response to client
            handleError(ex);
        }
    } catch (Exception e) {
        // Use original origin returned exception
        handleError(ex);
    }
}
Also used : ErrorType(com.netflix.zuul.exception.ErrorType) OutboundErrorType(com.netflix.zuul.exception.OutboundErrorType) SessionContext(com.netflix.zuul.context.SessionContext) ClientException(com.netflix.client.ClientException) ClientException(com.netflix.client.ClientException) ZuulException(com.netflix.zuul.exception.ZuulException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutboundException(com.netflix.zuul.exception.OutboundException)

Example 3 with ErrorType

use of com.netflix.zuul.exception.ErrorType in project zuul by Netflix.

the class NettyRequestAttemptFactory method mapNettyToOutboundException.

public OutboundException mapNettyToOutboundException(final Throwable t, final SessionContext context) {
    if (t instanceof OutboundException) {
        return (OutboundException) t;
    }
    // Map this throwable to zuul's OutboundException.
    final ErrorType errorType = mapNettyToOutboundErrorType(t);
    final RequestAttempts attempts = RequestAttempts.getFromSessionContext(context);
    if (errorType == OTHER) {
        return new OutboundException(errorType, attempts, t);
    }
    return new OutboundException(errorType, attempts);
}
Also used : ErrorType(com.netflix.zuul.exception.ErrorType) RequestAttempts(com.netflix.zuul.niws.RequestAttempts) OutboundException(com.netflix.zuul.exception.OutboundException)

Aggregations

ErrorType (com.netflix.zuul.exception.ErrorType)3 SessionContext (com.netflix.zuul.context.SessionContext)2 OutboundException (com.netflix.zuul.exception.OutboundException)2 ClientException (com.netflix.client.ClientException)1 OutboundErrorType (com.netflix.zuul.exception.OutboundErrorType)1 ZuulException (com.netflix.zuul.exception.ZuulException)1 RequestAttempts (com.netflix.zuul.niws.RequestAttempts)1 StatusCategory (com.netflix.zuul.stats.status.StatusCategory)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1