Skip to content

Commit

Permalink
PI-2391: Handle other exceptions (#4094)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 authored Aug 1, 2024
1 parent 9540e9e commit 62b978f
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import jakarta.json.JsonValue
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationContext
import org.springframework.http.ResponseEntity
import org.springframework.security.access.AccessDeniedException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.client.HttpStatusCodeException
import uk.gov.justice.digital.hmpps.advice.ControllerAdvice
import uk.gov.justice.digital.hmpps.exception.InvalidRequestException
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import java.io.StringReader
import java.lang.reflect.InvocationTargetException
import java.net.URI
import kotlin.reflect.KParameter
import org.springframework.security.access.AccessDeniedException

@Service
class CommunityApiService(
Expand All @@ -43,12 +46,13 @@ class CommunityApiService(
} catch (ex: InvocationTargetException) {
when (val cause = ex.cause) {
is AccessDeniedException -> controllerAdvice.handleAccessDenied(cause)
is NotFoundException -> controllerAdvice.handleNotFound(cause)
is InvalidRequestException -> controllerAdvice.handleInvalidRequest(cause)
is MethodArgumentNotValidException -> controllerAdvice.handleMethodArgumentNotValid(cause)
else -> throw ex
}
}
return mapper.writeValueAsString(
response
)
return mapper.writeValueAsString(response)
}

fun generateValue(param: KParameter, originalValue: Map<*, *>, paramNames: List<String>): Any? {
Expand Down

0 comments on commit 62b978f

Please sign in to comment.