![JAR search and dependency download from the Maven repository](/logo.png)
fr.whimtrip.ext.jwhtscrapper.exception.RequestFailedException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whimtrip-ext-scrapper Show documentation
Show all versions of whimtrip-ext-scrapper Show documentation
Fully featured highly pluggable and customizable Java scrapping framework
The newest version!
package fr.whimtrip.ext.jwhtscrapper.exception;
import org.asynchttpclient.Response;
/**
* Part of project jwht-scrapper
* Created on 29/07/18
*
*
* Thrown when requests failed for unknown reasons such as client/server
* side HTTP exception.
*
*
* @author Louis-wht
* @since 1.0.0
*/
public class RequestFailedException extends ScrapperException {
private static final int MAX_BODY_LENGTH = 1000;
public RequestFailedException(Response resp)
{
super(
String.format(
"Http request failed with status %s - %s and body %s",
resp.getStatusCode(),
resp.getStatusText(),
buildBody(resp)
)
);
}
private static String buildBody(Response resp) {
String body = resp.getResponseBody();
if(body.length() > MAX_BODY_LENGTH)
body = body.substring(0, MAX_BODY_LENGTH);
return body;
}
public RequestFailedException(String errorMessage) {
super(errorMessage);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy