You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
package com.crawler.exception.handler;
|
|
|
|
import com.crawler.exception.ConfigurationException;
|
|
import com.crawler.exception.InvalidUrlException;
|
|
import com.crawler.exception.UnsupportedCrawlerException;
|
|
import com.crawler.exception.ExceptionHandler;
|
|
import com.crawler.view.CrawlerView;
|
|
|
|
public class ConfigurationExceptionHandler implements ExceptionHandler {
|
|
@Override
|
|
public void handle(Exception e, CrawlerView view) {
|
|
if (e instanceof InvalidUrlException) {
|
|
InvalidUrlException ex = (InvalidUrlException) e;
|
|
view.showErrorMessage("无效的URL格式: " + ex.getInvalidUrl());
|
|
} else if (e instanceof UnsupportedCrawlerException) {
|
|
UnsupportedCrawlerException ex = (UnsupportedCrawlerException) e;
|
|
view.showErrorMessage("未找到支持该URL的爬虫: " + ex.getUrl());
|
|
} else {
|
|
view.showErrorMessage("配置异常: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Class<? extends Exception> getSupportedExceptionType() {
|
|
return ConfigurationException.class;
|
|
}
|
|
}
|