15 changed files with 213 additions and 56 deletions
@ -1,11 +0,0 @@ |
|||
package internal.hw.crawler.strategies.crawl; |
|||
|
|||
public class CrawlException extends Exception { |
|||
public CrawlException(String message) { |
|||
super(message); |
|||
} |
|||
|
|||
public CrawlException(String message, Throwable cause) { |
|||
super(message, cause); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package internal.hw.crawler.strategies.crawl; |
|||
|
|||
import java.net.URL; |
|||
|
|||
public class CrawlNetworkException extends CrawlerException { |
|||
private final int statusCode; |
|||
private final int attempts; |
|||
|
|||
public CrawlNetworkException(String message, URL url) { |
|||
this(message, null, url, -1, 0); |
|||
} |
|||
|
|||
public CrawlNetworkException(String message, Throwable cause, URL url) { |
|||
this(message, cause, url, -1, 0); |
|||
} |
|||
|
|||
public CrawlNetworkException(String message, Throwable cause, URL url, int attempts) { |
|||
this(message, cause, url, -1, attempts); |
|||
} |
|||
|
|||
public CrawlNetworkException(String message, Throwable cause, URL url, int statusCode, int attempts) { |
|||
super(message, url, cause); |
|||
this.statusCode = statusCode; |
|||
this.attempts = attempts; |
|||
} |
|||
|
|||
public int getStatusCode() { |
|||
return statusCode; |
|||
} |
|||
|
|||
public int getAttempts() { |
|||
return attempts; |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
package internal.hw.crawler.strategies.crawl; |
|||
|
|||
import java.net.URL; |
|||
|
|||
public class CrawlParseException extends CrawlerException { |
|||
public CrawlParseException(String message) { |
|||
super(message); |
|||
} |
|||
|
|||
public CrawlParseException(String message, URL url) { |
|||
super(message, url); |
|||
} |
|||
|
|||
public CrawlParseException(String message, URL url, Throwable cause) { |
|||
super(message, url, cause); |
|||
} |
|||
|
|||
public static class ElementNotFoundException extends CrawlParseException { |
|||
private final String selector; |
|||
|
|||
public ElementNotFoundException(String selector, URL url) { |
|||
super("Missing element '" + selector + "' in page: " + url, url); |
|||
this.selector = selector; |
|||
} |
|||
|
|||
public String getSelector() { |
|||
return selector; |
|||
} |
|||
} |
|||
|
|||
public static class IdExtractionException extends CrawlParseException { |
|||
private final String pattern; |
|||
|
|||
public IdExtractionException(URL url, String pattern) { |
|||
super("Cannot determine id for " + url + " (pattern: " + pattern + ")", url); |
|||
this.pattern = pattern; |
|||
} |
|||
|
|||
public String getPattern() { |
|||
return pattern; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
package internal.hw.crawler.strategies.crawl; |
|||
|
|||
import java.net.URL; |
|||
|
|||
public class CrawlUnsupportedException extends CrawlerException { |
|||
public CrawlUnsupportedException(URL url) { |
|||
super("Unsupported site: " + url, url); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
package internal.hw.crawler.strategies.crawl; |
|||
|
|||
import java.net.URL; |
|||
|
|||
public abstract class CrawlerException extends RuntimeException { |
|||
private final URL url; |
|||
|
|||
public CrawlerException(String message) { |
|||
super(message); |
|||
this.url = null; |
|||
} |
|||
|
|||
public CrawlerException(String message, Throwable cause) { |
|||
super(message, cause); |
|||
this.url = null; |
|||
} |
|||
|
|||
public CrawlerException(String message, URL url) { |
|||
super(message); |
|||
this.url = url; |
|||
} |
|||
|
|||
public CrawlerException(String message, URL url, Throwable cause) { |
|||
super(message, cause); |
|||
this.url = url; |
|||
} |
|||
|
|||
public URL getUrl() { |
|||
return url; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue