Skip to content

Commit 3e9e47e

Browse files
committed
update
1 parent 3741ac0 commit 3e9e47e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/guides/code_examples/error_handling/change_handle_error_status.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Using a placeholder refresh token for this example
1010
REFRESH_TOKEN = 'PLACEHOLDER'
11-
UNAUTHORIZED_STATUS_CODE = 401
11+
UNAUTHORIZED_CODE = 401
1212

1313

1414
async def main() -> None:
@@ -17,14 +17,14 @@ async def main() -> None:
1717
# Only treat 403 as a blocking status code, not 401
1818
session_pool=SessionPool(create_session_settings={'blocked_status_codes': [403]}),
1919
# Don't treat 401 responses as errors
20-
ignore_http_error_status_codes=[401],
20+
ignore_http_error_status_codes=[UNAUTHORIZED_CODE],
2121
)
2222

2323
@crawler.router.default_handler
2424
async def default_handler(context: HttpCrawlingContext) -> None:
2525
context.log.info(f'Processing {context.request.url} ...')
2626
# Now we can handle 401 responses ourselves
27-
if context.http_response.status_code == UNAUTHORIZED_STATUS_CODE:
27+
if context.http_response.status_code == UNAUTHORIZED_CODE:
2828
# Get a fresh access token
2929
headers = {'authorization': f'Bearer {REFRESH_TOKEN}'}
3030
response = await context.send_request(
@@ -38,7 +38,7 @@ async def default_handler(context: HttpCrawlingContext) -> None:
3838
}
3939
context.request.headers = HttpHeaders(new_headers)
4040
# Trigger a retry with our updated headers
41-
raise HttpStatusCodeError('Unauthorized', status_code=401)
41+
raise HttpStatusCodeError('Unauthorized', status_code=UNAUTHORIZED_CODE)
4242

4343
await crawler.run(['http://httpbingo.org/status/401'])
4444

0 commit comments

Comments
 (0)