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

Refactor risk endpoints to return empty data when upstream returns 403 #444

Closed
wants to merge 1 commit into from
Closed
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,8 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.PageRequest
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
Expand Down Expand Up @@ -33,6 +35,13 @@ class RiskPredictorScoresController(
if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
throw EntityNotFoundException("Could not find person with id: $hmppsId")
}

if (response.hasError(UpstreamApiError.Type.FORBIDDEN)) {
val emptyData = emptyList<RiskPredictorScore>()
val emptyPage = PageImpl(emptyData, PageRequest.of(page - 1, perPage), 0)
return PaginatedResponse(emptyPage)
}

auditService.createEvent("GET_PERSON_RISK_SCORES", mapOf("hmppsId" to hmppsId))
return response.data.paginateWith(page, perPage)
}
Expand Down
Loading