Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return InvalidRequest for invalidPayload #1265

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading