mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
- Re-throw as a ValidationError - Results in a 400 error, not a 500 (cherry picked from commit 5f3d3b28b367e4ead79aeafc34c8c8da4d7564cf) Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
parent
afa7ed873f
commit
946fe2df29
@ -18,6 +18,7 @@ import InvenTree.helpers
|
|||||||
import order.models
|
import order.models
|
||||||
import part.models
|
import part.models
|
||||||
from InvenTree.api import MetadataView
|
from InvenTree.api import MetadataView
|
||||||
|
from InvenTree.exceptions import log_error
|
||||||
from InvenTree.filters import InvenTreeSearchFilter
|
from InvenTree.filters import InvenTreeSearchFilter
|
||||||
from InvenTree.mixins import ListAPI, RetrieveAPI, RetrieveUpdateDestroyAPI
|
from InvenTree.mixins import ListAPI, RetrieveAPI, RetrieveUpdateDestroyAPI
|
||||||
from stock.models import StockItem, StockItemAttachment
|
from stock.models import StockItem, StockItemAttachment
|
||||||
@ -181,6 +182,7 @@ class ReportPrintMixin:
|
|||||||
# Start with a default report name
|
# Start with a default report name
|
||||||
report_name = "report.pdf"
|
report_name = "report.pdf"
|
||||||
|
|
||||||
|
try:
|
||||||
# Merge one or more PDF files into a single download
|
# Merge one or more PDF files into a single download
|
||||||
for item in items_to_print:
|
for item in items_to_print:
|
||||||
report = self.get_object()
|
report = self.get_object()
|
||||||
@ -254,6 +256,17 @@ class ReportPrintMixin:
|
|||||||
inline=inline,
|
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):
|
def get(self, request, *args, **kwargs):
|
||||||
"""Default implementation of GET for a print endpoint.
|
"""Default implementation of GET for a print endpoint.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user