package org.jeecg.modules.okki.translate.tools;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkBaseException;
import com.amazonaws.http.HttpResponse;
import com.amazonaws.http.HttpResponseHandler;

public class ErrorHandler implements HttpResponseHandler<SdkBaseException> {
    @Override
    public SdkBaseException handle(HttpResponse httpResponse)  {
        int status = httpResponse.getStatusCode();
        String message = httpResponse.getStatusText();
        if(status < 200 || status >= 300) {
            AmazonServiceException ase = new AmazonServiceException("Unexpected status: " + status + " " + message);
            ase.setStatusCode(status);
            return ase;
        }
        return null;
    }

    @Override
    public boolean needsConnectionLeftOpen() {
        return false;
    }
}