Skip to content

Commit

Permalink
APIS-7007 Add additional logging when returning a bad request (#118)
Browse files Browse the repository at this point in the history
* APIS-7007 Add additional logging when returing a bad request

* APIS-7007 Add additional logging when returing a bad request
  • Loading branch information
petekirby-ee authored Nov 1, 2024
1 parent 840568e commit 76374a7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/uk/gov/hmrc/apipublisher/controllers/PublisherController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,21 @@ class PublisherController @Inject() (
private val ER = EitherTHelper.make[Result]

private val mapBusinessErrorsToResults: PublishError => Result = _ match {
case err: DefinitionFileNotFound => BadRequest(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileNoBodyReturned => BadRequest(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileUnprocessableEntity => UnprocessableEntity(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileFailedSchemaValidation => UnprocessableEntity(error(ErrorCode.INVALID_API_DEFINITION, Json.toJson(err.error)))
case err: GenericValidationFailure => BadRequest(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileNotFound =>
logger.warn(s"${ErrorCode.INVALID_API_DEFINITION} - DefinitionFileNotFound: ${err.message}")
BadRequest(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileNoBodyReturned =>
logger.warn(s"${ErrorCode.INVALID_API_DEFINITION} - DefinitionFileNoBodyReturned: ${err.message}")
BadRequest(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileUnprocessableEntity =>
logger.warn(s"${ErrorCode.INVALID_API_DEFINITION} - DefinitionFileUnprocessableEntity: ${err.message}")
UnprocessableEntity(error(ErrorCode.INVALID_API_DEFINITION, err.message))
case err: DefinitionFileFailedSchemaValidation =>
logger.warn(s"${ErrorCode.INVALID_API_DEFINITION} - DefinitionFileFailedSchemaValidation: ${err.message}")
UnprocessableEntity(error(ErrorCode.INVALID_API_DEFINITION, Json.toJson(err.error)))
case err: GenericValidationFailure =>
logger.warn(s"${ErrorCode.INVALID_API_DEFINITION} - GenericValidationFailure: ${err.message}")
BadRequest(error(ErrorCode.INVALID_API_DEFINITION, err.message))
}

private def ensureAuthorised(implicit request: Request[JsValue]): Option[Result] = {
Expand Down

0 comments on commit 76374a7

Please sign in to comment.