Skip to content

Commit c298b4b

Browse files
committed
Add a DEFAULT_ERRBACK_NAME to settings
This will allow the ability to change the non-standard behavior of sending exceptions to the `parse` method of the spider without introducing a breaking change to scrapyrt. It also introduces some documentation of the existing behavior.
1 parent fc97dd1 commit c298b4b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/source/api.rst

+7
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,13 @@ Encoding that's used to encode log messages.
517517

518518
Default: ``utf-8``.
519519

520+
DEFAULT_ERRBACK_NAME
521+
~~~~~~~~
522+
523+
The name of the default errback method to call on the spider in case of an exception. The default is to use the ``parse`` method of the spider, which is non-standard to scrapy and may interfere with the use of middlewares which implement the ``process_spider_exception`` method, so use a setting of ``None`` here if you don't want to change the default scrapy exception handling.
524+
525+
Default: ``parse``. Use the ``parse`` method on scrapy spider to handle exceptions. Be aware that this is non-standard to typical scrapy spiders.
526+
520527

521528
Spider settings
522529
---------------

scrapyrt/conf/default_settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131
# disable in production
3232
DEBUG = True
3333

34-
TWISTED_REACTOR = None
34+
TWISTED_REACTOR = None
35+
36+
DEFAULT_ERRBACK_NAME = 'parse'

scrapyrt/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, spider_name, request_kwargs,
120120
# because we need to know if spider has method available
121121
self.callback_name = request_kwargs.pop('callback', None) or 'parse'
122122
# do the same for errback
123-
self.errback_name = request_kwargs.pop('errback', None)
123+
self.errback_name = request_kwargs.pop('errback', None) or app_settings.DEFAULT_ERRBACK_NAME
124124

125125
if request_kwargs.get("url"):
126126
self.request = self.create_spider_request(deepcopy(request_kwargs))

0 commit comments

Comments
 (0)