Skip to content

Commit

Permalink
fix: remove edge cases on some incorrect URLs and return a standard 4…
Browse files Browse the repository at this point in the history
…05 error
  • Loading branch information
bobeal committed Dec 18, 2023
1 parent 32ae350 commit b7ed99b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ class EntityHandler(
{ it }
)

@DeleteMapping("/", "")
fun handleMissingEntityIdOnDelete(): ResponseEntity<*> =
missingPathErrorResponse("Missing entity id when trying to delete an entity")

/**
* Implements 6.6.3.1 - Append Entity Attributes
*
Expand Down Expand Up @@ -488,7 +484,7 @@ class EntityHandler(
{ it }
)

@DeleteMapping("/attrs/{attrId}", "/{entityId}/attrs")
@DeleteMapping("/attrs/{attrId}")
fun handleMissingEntityIdOrAttributeOnDeleteAttribute(): ResponseEntity<*> =
missingPathErrorResponse("Missing entity id or attribute id when trying to delete an attribute")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,11 @@ class TemporalEntityHandler(

@PatchMapping(
"/attrs/{attrId}/{instanceId}",
"/{entityId}/attrs/{instanceId}",
"/attrs/{instanceId}",
"/{entityId}/attrs",
"/attrs"
)
fun handleMissingParametersOnModifyInstanceTemporal(): ResponseEntity<*> =
missingPathErrorResponse(
"Missing some parameter(entity id, attribute id, instance id) when trying to modify temporal entity"
"Missing some parameter (entity id, attribute id, instance id) when trying to modify temporal entity"
)

/**
Expand All @@ -277,10 +274,6 @@ class TemporalEntityHandler(
{ it }
)

@DeleteMapping("/", "")
fun handleMissingEntityIdOnDeleteTemporalEntity(): ResponseEntity<*> =
missingPathErrorResponse("Missing entity id when trying to delete temporal entity")

/**
* Implements 6.21.3.1 - Delete Attribute from Temporal Representation of an Entity
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.springframework.http.ProblemDetail
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.server.MethodNotAllowedException
import org.springframework.web.server.NotAcceptableStatusException
import org.springframework.web.server.UnsupportedMediaTypeStatusException

Expand Down Expand Up @@ -65,6 +66,8 @@ class ExceptionHandler {
HttpStatus.NOT_ACCEPTABLE,
NotAcceptableResponse(cause.message)
)
is MethodNotAllowedException ->
ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(cause.body)
is NonexistentTenantException -> generateErrorResponse(
HttpStatus.NOT_FOUND,
NonexistentTenantResponse(cause.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ class SubscriptionHandler(
{ it }
)

@PatchMapping("/", "")
fun handleMissingIdOnUpdate(): ResponseEntity<*> =
missingPathErrorResponse("Missing id when trying to update a subscription")

/**
* Implements 6.11.3.3 - Delete Subscription
*/
Expand All @@ -185,10 +181,6 @@ class SubscriptionHandler(
{ it }
)

@DeleteMapping("/", "")
fun handleMissingIdOnDelete(): ResponseEntity<*> =
missingPathErrorResponse("Missing id when trying to delete a subscription")

private suspend fun checkSubscriptionExists(subscriptionId: URI): Either<APIException, Unit> =
subscriptionService.exists(subscriptionId)
.flatMap {
Expand Down

0 comments on commit b7ed99b

Please sign in to comment.