Skip to content

Commit

Permalink
fix(transport): Throw explicit exception when a required header is mi…
Browse files Browse the repository at this point in the history
…ssing
  • Loading branch information
andacata committed Mar 21, 2024
1 parent 0230204 commit b66fdf2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ inline fun <reified T> HttpResponse.parsePaginatedBody(offset: Int): OcpiRespons
.let { parsedBody ->
OcpiResponseBody(
data = parsedBody.data?.toSearchResult(
totalCount = getHeader(Header.X_TOTAL_COUNT)!!.toInt(),
limit = getHeader(Header.X_LIMIT)!!.toInt(),
totalCount = getHeader(Header.X_TOTAL_COUNT)?.toInt()
?: throw OcpiToolkitMissingRequiredResponseHeaderException(Header.X_TOTAL_COUNT),
limit = getHeader(Header.X_LIMIT)?.toInt()
?: throw OcpiToolkitMissingRequiredResponseHeaderException(Header.X_LIMIT),
offset = offset,
nextPageUrl = getHeader(Header.LINK)?.split("<")?.get(1)?.split(">")?.first()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ class OcpiToolkitResponseParsingException(
) : Exception(
"Response cannot be parsed. URL='$urlCalled', error='${cause.message}'"
)

class OcpiToolkitMissingRequiredResponseHeaderException(
header: String
) : Exception(
"""Required header "$header" not found in the response from the server"""
)

0 comments on commit b66fdf2

Please sign in to comment.