Skip to content

Commit

Permalink
Merge pull request #28 from hmrc/TAV-302C
Browse files Browse the repository at this point in the history
TAV-302: Fixed error reporting on deserialization failure
  • Loading branch information
beyond-code-github authored Jun 30, 2021
2 parents 424e892 + 156aa82 commit 4f6c0b4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/util/AddressLookupJsonErrorHandler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2021 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package util

import play.api.Configuration
import play.api.http.Status.BAD_REQUEST
import play.api.mvc.Results.BadRequest
import play.api.mvc.{RequestHeader, Result}
import uk.gov.hmrc.play.audit.http.connector.AuditConnector
import uk.gov.hmrc.play.bootstrap.backend.http.JsonErrorHandler
import uk.gov.hmrc.play.bootstrap.config.HttpAuditEvent

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class AddressLookupJsonErrorHandler @Inject()(auditConnector: AuditConnector,
httpAuditEvent: HttpAuditEvent, configuration: Configuration)(
implicit ec: ExecutionContext) extends JsonErrorHandler(auditConnector, httpAuditEvent, configuration) {

override def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] = {
(statusCode, message) match {
case (BAD_REQUEST, msg) if msg.startsWith("Json validation error") =>
Future.successful(BadRequest("error=missing or badly-formed postcode parameter"))
case _ => super.onClientError(request, statusCode, message)
}
}
}
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ play.http.router = app.Routes
#play 2.5 requires an application secret
play.crypto.secret: "H7dVw$PlJiD)^U,oa4TA1pa]pT:4ETLqbL&2P=n6T~p,A*}^.Y46@PQOV~9(B09Hc]t7-hsf~&@w=zH"

play.http.errorHandler = "uk.gov.hmrc.play.bootstrap.http.JsonErrorHandler"
play.http.errorHandler = "util.AddressLookupJsonErrorHandler"

play.ws.timeout.request = 70000ms # 70 secs

Expand Down

0 comments on commit 4f6c0b4

Please sign in to comment.