Search in sources :

Example 1 with ConnectionException

use of com.github.df.restypass.exception.execute.ConnectionException in project RestyPass by darren-fu.

the class RestyFuture method get.

@Override
public T get() throws RestyException {
    Response response;
    try {
        response = future.get();
    } catch (InterruptedException | ExecutionException e) {
        future.abort(e);
        log.warn("获取响应失败:{}", e.getMessage());
        if (this.getRestyCommand().isAsyncArg() || this.getRestyCommand().isAsyncReturn()) {
            throw new RestyException(e);
        }
        response = FailedResponse.create(new ConnectionException(e));
    }
    T resp = (T) ResponseConverterContext.DEFAULT.convertResponse(restyCommand, response);
    if (restyCommand.isAsyncReturn() || restyCommand.isAsyncArg()) {
        if (RestyCommandStatus.FAILED == restyCommand.getStatus() && restyCommand.getFailException() != null) {
            throw restyCommand.getFailException();
        }
    }
    return resp;
}
Also used : FailedResponse(com.github.df.restypass.http.pojo.FailedResponse) Response(org.asynchttpclient.Response) RestyException(com.github.df.restypass.exception.execute.RestyException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(com.github.df.restypass.exception.execute.ConnectionException)

Example 2 with ConnectionException

use of com.github.df.restypass.exception.execute.ConnectionException in project RestyPass by darren-fu.

the class RestyFuture method get.

@SuppressWarnings("NullableProblems")
@Override
public T get(long timeout, TimeUnit unit) throws RestyException {
    Response response;
    try {
        response = future.get(timeout, unit);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        future.abort(e);
        log.error("获取响应失败:{}", e.getMessage());
        if (this.getRestyCommand().isAsyncArg() || this.getRestyCommand().isAsyncReturn()) {
            throw new RestyException(e);
        }
        response = FailedResponse.create(new ConnectionException(e));
    }
    T resp = (T) ResponseConverterContext.DEFAULT.convertResponse(restyCommand, response);
    if (restyCommand.isAsyncReturn() || restyCommand.isAsyncArg()) {
        if (RestyCommandStatus.FAILED == restyCommand.getStatus() && restyCommand.getFailException() != null) {
            throw restyCommand.getFailException();
        }
    }
    return resp;
}
Also used : FailedResponse(com.github.df.restypass.http.pojo.FailedResponse) Response(org.asynchttpclient.Response) RestyException(com.github.df.restypass.exception.execute.RestyException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(com.github.df.restypass.exception.execute.ConnectionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ConnectionException (com.github.df.restypass.exception.execute.ConnectionException)2 RestyException (com.github.df.restypass.exception.execute.RestyException)2 FailedResponse (com.github.df.restypass.http.pojo.FailedResponse)2 ExecutionException (java.util.concurrent.ExecutionException)2 Response (org.asynchttpclient.Response)2 TimeoutException (java.util.concurrent.TimeoutException)1