Skip to content

Commit

Permalink
fix: return InvalidRequest for invalidPayload (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasBousselin authored Nov 18, 2024
1 parent 1bd270a commit 6d22cf2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.egm.stellio.shared.util

import com.egm.stellio.shared.model.BadRequestDataException
import com.egm.stellio.shared.model.InvalidRequestException
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_JSON_TERM
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_VALUE_TERM
import com.fasterxml.jackson.core.JsonProcessingException
Expand Down Expand Up @@ -31,7 +31,7 @@ object JsonUtils {
mapper.typeFactory.constructMapLikeType(Map::class.java, String::class.java, Any::class.java)
)
} catch (e: JsonProcessingException) {
throw BadRequestDataException(e.message!!)
throw InvalidRequestException(e.message!!)
}

fun String.deserializeAsMap(): Map<String, Any> =
Expand All @@ -49,7 +49,7 @@ object JsonUtils {
mapper.typeFactory.constructCollectionType(MutableList::class.java, Map::class.java)
)
} catch (e: JsonProcessingException) {
throw BadRequestDataException(e.message!!)
throw InvalidRequestException(e.message!!)
}

fun String.deserializeAsList(): List<Map<String, Any>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.egm.stellio.shared.model.AttributeDeleteAllInstancesEvent
import com.egm.stellio.shared.model.AttributeDeleteEvent
import com.egm.stellio.shared.model.AttributeReplaceEvent
import com.egm.stellio.shared.model.AttributeUpdateEvent
import com.egm.stellio.shared.model.BadRequestDataException
import com.egm.stellio.shared.model.EntityCreateEvent
import com.egm.stellio.shared.model.EntityDeleteEvent
import com.egm.stellio.shared.model.EntityEvent
import com.egm.stellio.shared.model.EntityReplaceEvent
import com.egm.stellio.shared.model.InvalidRequestException
import com.egm.stellio.shared.util.JsonLdUtils.expandJsonLdFragment
import com.egm.stellio.shared.util.JsonUtils.deserializeAs
import com.egm.stellio.shared.util.JsonUtils.deserializeAsMap
Expand Down Expand Up @@ -153,7 +153,7 @@ class JsonUtilsTests {
}

@Test
fun `it should throw an BadRequestDataException exception if the JSON-LD fragment is not a valid JSON document`() {
fun `it should throw an InvalidRequest exception if the JSON-LD fragment is not a valid JSON document`() {
val rawEntity =
"""
{
Expand All @@ -162,7 +162,7 @@ class JsonUtilsTests {
}
""".trimIndent()

val exception = assertThrows<BadRequestDataException> {
val exception = assertThrows<InvalidRequestException> {
rawEntity.deserializeAsMap()
}
assertThat(exception.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ExceptionHandlerTests {
.exchange()
.expectStatus().isEqualTo(HttpStatus.BAD_REQUEST)
.expectBody()
.jsonPath("$..type").isEqualTo("https://uri.etsi.org/ngsi-ld/errors/BadRequestData")
.jsonPath("$..type").isEqualTo("https://uri.etsi.org/ngsi-ld/errors/InvalidRequest")
}

@Test
Expand Down

0 comments on commit 6d22cf2

Please sign in to comment.