# Improvement PUT API
* improves error processing and response on PUT endpoint * consolidates improved error processing into central method for all API endpoints
This commit is contained in:
@@ -6,6 +6,7 @@ Created on: 24.01.22
|
||||
|
||||
"""
|
||||
import json
|
||||
import uuid
|
||||
from abc import abstractmethod
|
||||
|
||||
from django.contrib.gis import geos
|
||||
@@ -171,13 +172,20 @@ class AbstractModelAPISerializer:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if not id:
|
||||
raise ValueError("No id provided. The id is expected to live in the URL!")
|
||||
|
||||
# First if there is an external identifier linked to an internal one, so we can continue with the internal
|
||||
try:
|
||||
ext_id = ExternalIdentifier.objects.get(external_id=id)
|
||||
id = ext_id.internal_id
|
||||
except ObjectDoesNotExist:
|
||||
# No external id found - let's hope the given id exists internally
|
||||
pass
|
||||
# Not found as external id - let's check whether this is a valid uuid and therefore
|
||||
# potentially an internal id
|
||||
try:
|
||||
uuid.UUID(id)
|
||||
except ValueError:
|
||||
raise AssertionError(f"'{id}' is neither a known external identifier nor a valid uuid.")
|
||||
|
||||
obj = self.model.objects.get(
|
||||
id=id,
|
||||
|
||||
Reference in New Issue
Block a user