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.
26 lines
969 B
26 lines
969 B
package com.crawler.exception.handler;
|
|
|
|
import com.crawler.exception.HttpRequestException;
|
|
import com.crawler.exception.NetworkException;
|
|
import com.crawler.exception.TimeoutException;
|
|
import com.crawler.exception.ExceptionHandler;
|
|
import com.crawler.view.CrawlerView;
|
|
|
|
public class NetworkExceptionHandler implements ExceptionHandler {
|
|
@Override
|
|
public void handle(Exception e, CrawlerView view) {
|
|
if (e instanceof HttpRequestException) {
|
|
HttpRequestException ex = (HttpRequestException) e;
|
|
view.showErrorMessage("HTTP请求失败,状态码: " + ex.getStatusCode());
|
|
} else if (e instanceof TimeoutException) {
|
|
view.showErrorMessage("网络连接超时,请稍后重试");
|
|
} else {
|
|
view.showErrorMessage("网络异常: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Class<? extends Exception> getSupportedExceptionType() {
|
|
return NetworkException.class;
|
|
}
|
|
}
|