Pass exception to onError. Fixes #1005.

pull/1012/head
Sutra Zhou 4 years ago
parent dcfd238413
commit 4e8a086dae

@ -320,7 +320,7 @@ public class Spider implements Runnable, Task {
processRequest(request);
onSuccess(request);
} catch (Exception e) {
onError(request);
onError(request, e);
logger.error("process request " + request + " error", e);
} finally {
pageCount.incrementAndGet();
@ -338,10 +338,19 @@ public class Spider implements Runnable, Task {
logger.info("Spider {} closed! {} pages downloaded.", getUUID(), pageCount.get());
}
/**
* @deprecated Use {@link #onError(Request, Exception)} instead.
*/
@Deprecated
protected void onError(Request request) {
}
protected void onError(Request request, Exception e) {
this.onError(request);
if (CollectionUtils.isNotEmpty(spiderListeners)) {
for (SpiderListener spiderListener : spiderListeners) {
spiderListener.onError(request);
spiderListener.onError(request, e);
}
}
}

@ -10,5 +10,14 @@ public interface SpiderListener {
public void onSuccess(Request request);
/**
* @deprecated Use {@link #onError(Request, Exception)} instead.
*/
@Deprecated
public void onError(Request request);
default void onError(Request request, Exception e) {
this.onError(request);
}
}

Loading…
Cancel
Save