All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.whimtrip.ext.jwhtscrapper.exception.RequestFailedException Maven / Gradle / Ivy

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