mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Handle errors when printing reports (#5360)
- Re-throw as a ValidationError - Results in a 400 error, not a 500
This commit is contained in:
parent
7e7d4d01a2
commit
5f3d3b28b3
@ -18,6 +18,7 @@ import InvenTree.helpers
|
||||
import order.models
|
||||
import part.models
|
||||
from InvenTree.api import MetadataView
|
||||
from InvenTree.exceptions import log_error
|
||||
from InvenTree.filters import InvenTreeSearchFilter
|
||||
from InvenTree.mixins import ListAPI, RetrieveAPI, RetrieveUpdateDestroyAPI
|
||||
from stock.models import StockItem, StockItemAttachment, StockLocation
|
||||
@ -183,6 +184,7 @@ class ReportPrintMixin:
|
||||
# Start with a default report name
|
||||
report_name = "report.pdf"
|
||||
|
||||
try:
|
||||
# Merge one or more PDF files into a single download
|
||||
for item in items_to_print:
|
||||
report = self.get_object()
|
||||
@ -256,6 +258,17 @@ class ReportPrintMixin:
|
||||
inline=inline,
|
||||
)
|
||||
|
||||
except Exception as exc:
|
||||
# Log the exception to the database
|
||||
log_error(request.path)
|
||||
|
||||
# Re-throw the exception to the client as a DRF exception
|
||||
raise ValidationError({
|
||||
'error': 'Report printing failed',
|
||||
'detail': str(exc),
|
||||
'path': request.path,
|
||||
})
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""Default implementation of GET for a print endpoint.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user