mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Reimplement error-report API endpoint (#6317)
- Removed in previous commit - b8b3dfc90e
- Adds unit tests to ensure it doesn't happen again
This commit is contained in:
parent
f85b773a50
commit
e7d926f983
@ -53,7 +53,10 @@ def log_error(path, error_name=None, error_info=None, error_data=None):
|
|||||||
if error_data:
|
if error_data:
|
||||||
data = error_data
|
data = error_data
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
data = '\n'.join(traceback.format_exception(kind, info, data))
|
data = '\n'.join(traceback.format_exception(kind, info, data))
|
||||||
|
except AttributeError:
|
||||||
|
data = 'No traceback information available'
|
||||||
|
|
||||||
# Log error to stderr
|
# Log error to stderr
|
||||||
logger.error(info)
|
logger.error(info)
|
||||||
|
@ -668,6 +668,13 @@ common_api_urls = [
|
|||||||
path('', BackgroundTaskOverview.as_view(), name='api-task-overview'),
|
path('', BackgroundTaskOverview.as_view(), name='api-task-overview'),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'error-report/',
|
||||||
|
include([
|
||||||
|
path('<int:pk>/', ErrorMessageDetail.as_view(), name='api-error-detail'),
|
||||||
|
path('', ErrorMessageList.as_view(), name='api-error-list'),
|
||||||
|
]),
|
||||||
|
),
|
||||||
# Project codes
|
# Project codes
|
||||||
path(
|
path(
|
||||||
'project-code/',
|
'project-code/',
|
||||||
|
@ -658,6 +658,30 @@ class PluginSettingsApiTest(PluginMixin, InvenTreeAPITestCase):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorReportTest(InvenTreeAPITestCase):
|
||||||
|
"""Unit tests for the error report API."""
|
||||||
|
|
||||||
|
def test_error_list(self):
|
||||||
|
"""Test error list."""
|
||||||
|
from InvenTree.exceptions import log_error
|
||||||
|
|
||||||
|
url = reverse('api-error-list')
|
||||||
|
response = self.get(url, expected_code=200)
|
||||||
|
self.assertEqual(len(response.data), 0)
|
||||||
|
|
||||||
|
# Throw an error!
|
||||||
|
log_error(
|
||||||
|
'test error', error_name='My custom error', error_info={'test': 'data'}
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self.get(url, expected_code=200)
|
||||||
|
self.assertEqual(len(response.data), 1)
|
||||||
|
|
||||||
|
err = response.data[0]
|
||||||
|
for k in ['when', 'info', 'data', 'path']:
|
||||||
|
self.assertIn(k, err)
|
||||||
|
|
||||||
|
|
||||||
class TaskListApiTests(InvenTreeAPITestCase):
|
class TaskListApiTests(InvenTreeAPITestCase):
|
||||||
"""Unit tests for the background task API endpoints."""
|
"""Unit tests for the background task API endpoints."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user