Skip to content

Commit 1367451

Browse files
timobrembeckclaudep
authored andcommitted
Add error_message field to Url model
1 parent ebb7a77 commit 1367451

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Unreleased
99
* `redirect_status_code`: The HTTP status code of the final request
1010
* `anchor_status`: The validity of the HTML hash anchor
1111
* `ssl_status` The validity of the SSL certificate
12+
* `error_message` The error message if the request failed
1213
* Add new properties to `Url` model:
1314
* `anchor_message`: The human-readable meaning of the `anchor_status`
1415
* `ssl_message` The human-readable meaning of the `ssl_status`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.db import migrations, models
2+
3+
4+
class Migration(migrations.Migration):
5+
6+
dependencies = [
7+
('linkcheck', '0009_url_add_ssl_status'),
8+
]
9+
10+
operations = [
11+
migrations.AddField(
12+
model_name='url',
13+
name='error_message',
14+
field=models.CharField(blank=True, default='', max_length=1024),
15+
),
16+
]

linkcheck/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Url(models.Model):
7676
status_code = models.IntegerField(choices=STATUS_CODE_CHOICES, null=True)
7777
redirect_status_code = models.IntegerField(choices=STATUS_CODE_CHOICES, null=True)
7878
message = models.CharField(max_length=1024, blank=True, null=True)
79+
error_message = models.CharField(max_length=1024, default='', blank=True)
7980
redirect_to = models.TextField(blank=True)
8081

8182
@property
@@ -239,6 +240,8 @@ def reset_for_check(self):
239240
self.status_code = None
240241
self.redirect_status_code = None
241242
self.ssl_status = None
243+
self.error_message = ''
244+
self.message = ''
242245

243246
def check_url(self, check_internal=True, check_external=True, external_recheck_interval=EXTERNAL_RECHECK_INTERVAL):
244247
"""
@@ -398,14 +401,16 @@ def check_external(self, external_recheck_interval=EXTERNAL_RECHECK_INTERVAL):
398401
except ReadTimeout:
399402
self.status = False
400403
self.message = 'Other Error: The read operation timed out'
404+
self.error_message = 'The read operation timed out'
401405
except ConnectionError as e:
402406
self.status = False
403-
self.message = format_connection_error(e)
407+
self.message = self.error_message = format_connection_error(e)
404408
if 'SSLError' in str(e):
405409
self.ssl_status = False
406410
except Exception as e:
407411
self.status = False
408412
self.message = f'Other Error: {e}'
413+
self.error_message = str(e)
409414
else:
410415
self.status = response.status_code < 300
411416
self.message = f"{response.status_code} {response.reason}"

0 commit comments

Comments
 (0)