Skip to content

Commit 7425cf5

Browse files
committed
Return 404 response if probation search cannot find hmpps id.
1 parent 7613e83 commit 7425cf5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/prison/PrisonController.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ class PrisonController(
4949
): DataResponse<Person?> {
5050
val response = getPersonService.getPrisoner(hmppsId)
5151

52-
if (response.hasErrorCausedBy(ENTITY_NOT_FOUND, causedBy = UpstreamApi.PRISONER_OFFENDER_SEARCH)) {
52+
if (response.hasErrorCausedBy(ENTITY_NOT_FOUND, causedBy = UpstreamApi.PROBATION_OFFENDER_SEARCH)) {
5353
throw EntityNotFoundException("Could not find person with hmppsId: $hmppsId")
5454
}
55+
if (response.hasErrorCausedBy(ENTITY_NOT_FOUND, causedBy = UpstreamApi.PRISONER_OFFENDER_SEARCH)) {
56+
throw EntityNotFoundException("Could not find prisoner with hmppsId: $hmppsId")
57+
}
5558

5659
auditService.createEvent("GET_PERSON_DETAILS", mapOf("hmppsId" to hmppsId))
5760
val data = response.data

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/prison/PrisonControllerTest.kt

+20
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ internal class PrisonControllerTest(
154154
result.response.status.shouldBe(404)
155155
}
156156

157+
it("returns 404 when NOMIS number is not found") {
158+
whenever(getPersonService.getPrisoner(hmppsId)).thenReturn(
159+
Response(
160+
data = null,
161+
errors =
162+
listOf(
163+
UpstreamApiError(
164+
type = ENTITY_NOT_FOUND,
165+
causedBy = UpstreamApi.PROBATION_OFFENDER_SEARCH,
166+
description = "NOMIS number not found",
167+
),
168+
),
169+
),
170+
)
171+
172+
val result = mockMvc.performAuthorised("$basePath/prisoners/$hmppsId")
173+
174+
result.response.status.shouldBe(404)
175+
}
176+
157177
it("returns 500 when prison/prisoners throws an unexpected error") {
158178

159179
whenever(getPrisonersService.execute("Barry", "Allen", "2023-03-01")).thenThrow(RuntimeException("Service error"))

0 commit comments

Comments
 (0)