use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.
the class OriginResponseReceiver method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof CompleteEvent) {
final CompleteReason reason = ((CompleteEvent) evt).getReason();
if ((reason != SESSION_COMPLETE) && (edgeProxy != null)) {
LOG.error("Origin request completed with reason other than COMPLETE: {}, {}", reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
final ZuulException ze = new ZuulException("CompleteEvent", reason.name(), true);
edgeProxy.errorFromOrigin(ze);
}
// See channelWrite() where these vars are first set onto the channel.
try {
super.userEventTriggered(ctx, evt);
} finally {
postCompleteHook(ctx, evt);
}
} else if (evt instanceof SslHandshakeCompletionEvent && !((SslHandshakeCompletionEvent) evt).isSuccess()) {
Throwable cause = ((SslHandshakeCompletionEvent) evt).cause();
ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).set(cause);
} else if (evt instanceof IdleStateEvent) {
if (edgeProxy != null) {
LOG.error("Origin request received IDLE event: {}", ChannelUtils.channelInfoForLogging(ctx.channel()));
edgeProxy.errorFromOrigin(new OutboundException(READ_TIMEOUT, edgeProxy.getRequestAttempts()));
}
super.userEventTriggered(ctx, evt);
} else {
super.userEventTriggered(ctx, evt);
}
}
use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.
the class RequestAttempt method setException.
public void setException(Throwable t) {
if (t != null) {
if (t instanceof ReadTimeoutException) {
error = "READ_TIMEOUT";
exceptionType = t.getClass().getSimpleName();
} else if (t instanceof OriginConnectException) {
OriginConnectException oce = (OriginConnectException) t;
if (oce.getErrorType() != null) {
error = oce.getErrorType().toString();
} else {
error = "ORIGIN_CONNECT_ERROR";
}
final Throwable cause = t.getCause();
if (cause != null) {
exceptionType = t.getCause().getClass().getSimpleName();
} else {
exceptionType = t.getClass().getSimpleName();
}
} else if (t instanceof OutboundException) {
OutboundException obe = (OutboundException) t;
error = obe.getOutboundErrorType().toString();
exceptionType = OutboundException.class.getSimpleName();
} else if (t instanceof SSLHandshakeException) {
error = t.getMessage();
exceptionType = t.getClass().getSimpleName();
cause = t.getCause().getMessage();
} else {
error = t.getMessage();
exceptionType = t.getClass().getSimpleName();
cause = Throwables.getStackTraceAsString(t);
}
}
}
use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.
the class ProxyEndpoint method handleOriginNonSuccessResponse.
protected void handleOriginNonSuccessResponse(final HttpResponse originResponse, DiscoveryResult chosenServer) {
final int respStatus = originResponse.status().code();
OutboundException obe;
StatusCategory statusCategory;
ClientException.ErrorType niwsErrorType;
if (respStatus == 503) {
// Treat 503 status from Origin similarly to connection failures, ie. we want to back off from this server
statusCategory = FAILURE_ORIGIN_THROTTLED;
niwsErrorType = ClientException.ErrorType.SERVER_THROTTLED;
obe = new OutboundException(OutboundErrorType.SERVICE_UNAVAILABLE, requestAttempts);
// TODO(carl-mastrangelo): pass in the clock for testing.
origin.stats().lastThrottleEvent(ZonedDateTime.now());
if (originConn != null) {
originConn.getServer().incrementSuccessiveConnectionFailureCount();
originConn.getServer().addToFailureCount();
originConn.flagShouldClose();
}
if (currentRequestStat != null) {
currentRequestStat.updateWithHttpStatusCode(respStatus);
currentRequestStat.serviceUnavailable();
}
} else {
statusCategory = FAILURE_ORIGIN;
niwsErrorType = ClientException.ErrorType.GENERAL;
obe = new OutboundException(OutboundErrorType.ERROR_STATUS_RESPONSE, requestAttempts);
if (currentRequestStat != null) {
currentRequestStat.updateWithHttpStatusCode(respStatus);
currentRequestStat.generalError();
}
}
obe.setStatusCode(respStatus);
long duration = 0;
if (currentRequestStat != null) {
duration = currentRequestStat.duration();
}
if (currentRequestAttempt != null) {
currentRequestAttempt.complete(respStatus, duration, obe);
}
// Flag this error with the ExecutionListener.
origin.onRequestExceptionWithServer(zuulRequest, chosenServer, attemptNum, new ClientException(niwsErrorType));
if ((isBelowRetryLimit()) && (isRetryable5xxResponse(zuulRequest, originResponse))) {
LOG.debug("Retrying: status={}, attemptNum={}, maxRetries={}, startedSendingResponseToClient={}, hasCompleteBody={}, method={}", respStatus, attemptNum, origin.getMaxRetriesForRequest(context), startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
// detach from current origin.
unlinkFromOrigin();
// retry request with different origin
passport.add(ORIGIN_RETRY_START);
origin.adjustRetryPolicyIfNeeded(zuulRequest);
proxyRequestToOrigin();
} else {
SessionContext zuulCtx = context;
LOG.info("Sending error to client: status={}, attemptNum={}, maxRetries={}, startedSendingResponseToClient={}, hasCompleteBody={}, method={}", respStatus, attemptNum, origin.getMaxRetriesForRequest(zuulCtx), startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
// This is a final response after all retries that will go to the client
zuulResponse = buildZuulHttpResponse(originResponse, statusCategory, obe);
invokeNext(zuulResponse);
}
}
use of com.netflix.zuul.exception.OutboundException 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);
}
Aggregations