500/1011 Unexpected Condition/Internal Server Error #1685

scala

(Yash Bhardwaj) #1

With reference to #1685 on git.

I’m facing the same error in my unmanaged service, I have multiple endpoints defined in descriptor, all are working fine except one. Here’s some related information:


  def setLimit: ServiceCall[SetLimitRequest, BaseResponse]
  def depositAmount: ServiceCall[SampleRequest, BaseResponse]

  override final def descriptor = {
    import Service._
    // @formatter:off
    named("service")
      .withCalls(
        restCall(Method.POST, "/api/v1/sample/sampleRequest", depositAmount),
        restCall(Method.POST, "/api/v1/sample/sampleEvent/event", setLimit)
      ).withAutoAcl(true)
    // @formatter:on
  }

Models:

  case class SetLimitRequest(token: String, userName: String, Id: String, details: String)
  case class BaseResponse(status: String, code: String, message: String)
  case class SampleRequest(token: String, userName: String, sample1: Double, sample2: String, sample3: String)


  object SampleRequest {
    implicit val format: Format[SampleRequest] = Json.format[SampleRequest]
  }
  object BaseResponse {
    implicit val format: Format[BaseResponse] = Json.format[BaseResponse]
  }
  object SetLimitRequest {
    implicit val format: Format[SetLimitRequest] = Json.format[SetLimitRequest]
  }

Requests:

service.setLimit.invoke(setLimitRequest).map { setLimitResponse =>
      println(s"set limit response: $setLimitResponse")
      setLimitResponse
    } // working fine


val sampleRequest = SampleRequest( "ad3ef9a5-ccf9-43d3-976a-3271345ad3c6",  "bd082e7c-5905-4570-9aff-0d33e5396439",  "da9beer6-7eca-4fb8-95a5-064b457b0800", 100000, 14.5, 120, "Sample Description" )

val res = service.sampleRequest.invoke(sampleRequest)
    res.map { response =>
      println(s"4. Response: $response")
      response
    }.recover {
      case ex: TransportException =>
        val x = getErrorResponse(ex.errorCode.http.toString, ex.errorCode.description)
        println(s"6. Cause: ${x}, \n\n\n\nMessage ${ex.exceptionMessage.name} \n\n\n ====>${ex.exceptionMessage.detail}")
        x
    }

The request is working fine in Postman or CURL, and the response is:

{
    "status": "SUCCESS",
    "code": "200",
    "message": "Sample Message."
}

so, ideally it should serialize like it is doing for other requests but with microservice it’s giving this:

com.lightbend.lagom.scaladsl.api.transport.TransportException:
–HTML-- (500/1011 Unexpected Condition/Internal Server Error)

	at com.lightbend.lagom.scaladsl.api.transport.TransportException$.$anonfun$fromCodeAndMessage$2(Exceptions.scala:223)
	at scala.Option.fold(Option.scala:175)
	at com.lightbend.lagom.scaladsl.api.transport.TransportException$.fromCodeAndMessage(Exceptions.scala:223)
	at com.lightbend.lagom.scaladsl.api.deser.DefaultExceptionSerializer.fromCodeAndMessage(ExceptionSerializer.scala:114)
	at com.lightbend.lagom.scaladsl.api.deser.DefaultExceptionSerializer.deserialize(ExceptionSerializer.scala:100)
	at com.lightbend.lagom.internal.scaladsl.client.ScaladslServiceApiBridge.exceptionSerializerDeserializeHttpException(ScaladslServiceApiBridge.scala:82)
	at com.lightbend.lagom.internal.scaladsl.client.ScaladslServiceApiBridge.exceptionSerializerDeserializeHttpException$(ScaladslServiceApiBridge.scala:80)
	at com.lightbend.lagom.internal.scaladsl.client.ScaladslClientServiceCallInvoker.exceptionSerializerDeserializeHttpException(ScaladslServiceClientInvoker.scala:110)
	at com.lightbend.lagom.internal.scaladsl.client.ScaladslClientServiceCallInvoker.exceptionSerializerDeserializeHttpException(ScaladslServiceClientInvoker.scala:110)
	at com.lightbend.lagom.internal.client.ClientServiceCallInvoker.$anonfun$makeStrictCall$3(ClientServiceCallInvoker.scala:222)
	at scala.util.Success.$anonfun$map$1(Try.scala:255)
	at scala.util.Success.map(Try.scala:213)
	at scala.concurrent.Future.$anonfun$map$1(Future.scala:292)
	at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:33)
	at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
	at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
	at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:85)
	at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
	at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
	at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:44)
	at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
	at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
	at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
	at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

Any guidances?

_Originally posted by @yash-lf in https://github.com/render_node/MDEyOklzc3VlQ29tbWVudDQ0OTM0NzM2Mw==/timeline/issue_comment#issuecomment-449347363


(Renato) #2

@yash-bhardwaj, are you calling the service from inside the same service? By injecting the service in another component?


(Yash Bhardwaj) #3

@renato I’m wiring a scheduler with Application loader and injecting the service in that Scheduler, then invoking the endpoints from an Associated class which has the instance of service in its constructor. Like:

abstract class LoanFrameApp(context: LagomApplicationContext) extends LagomApplication(context)
  with SlickPersistenceComponents with AhcWSComponents {

  override implicit lazy val actorSystem: ActorSystem = ActorSystem("MyActorSystem")

  override lazy val materializer: ActorMaterializer = ActorMaterializer()
  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[BasicService](wire[BasicServiceImpl])

  //Bind the external service in ServiceModule.
  lazy val externalService = serviceClient.implement[MyService]

  /**
    * Required DataModel's Injections
    */
 // code here

  override def connectionPool: ConnectionPool = new HikariCPConnectionPool(environment)

  override def jsonSerializerRegistry: JsonSerializerRegistry = new JsonSerializerLMS

  wire[ServiceScheduler]

}

Scheduler:

class ServiceScheduler @Inject()(service: MyService, system: ActorSystem, materializer: ActorMaterializer, configuration: Configuration, --Some more injecttions--)(implicit ec: ExecutionContext) {

val myServiceImpl = new MyServiceImpl(service: MyService, system: ActorSystem, materializer: ActorMaterializer, configuration: Configuration, --Other Injections--, ec)

// It is invoked Something like:
system.scheduler.schedule(2.seconds, 80.seconds)(myServiceImpl.sampleRequestImpl("SomeId"))
}

class MyServiceImpl(service: MyService, system: ActorSystem, materializer: ActorMaterializer, configuration: Configuration, --Other Injections--, implicit val ec: ExecutionContext) {

  def sampleRequestImpl(id: String): Future[BaseResponse] = {
    println(s"1. Hitting for sample Response: $id")
    val sampleRequest: SampleRequest =  //the request instance
    service.sampleRequest.invoke(sampleRequest).map {response =>
      println(s"4. Response: $response")
      response
    }.recover {
      case ex: TransportException =>
        val x = getErrorResponse(ex.errorCode.http.toString, ex.errorCode.description)
        println(s"6. Cause: ${x}, \n\n\n\nMessage ${ex.exceptionMessage.name} \n\n\n ====>${ex.exceptionMessage.name}")
        x
    }
  }
}

(Yash Bhardwaj) #4

at com.lightbend.lagom.scaladsl.api.deser.DefaultExceptionSerializer.deserialize(ExceptionSerializer.scala:100)

suggests that this a de-serialization thing, but I don’t see any Gap between the Model and the Output JSON.

Well, the HTML response is deserializable, meaning there’s nothing wrong with response type.

I can’t figure out why it is giving that HTML response.

@renato found something?


(Renato) #5

@yash-bhardwaj, it’s very hard to see why and how this is happening. Would you be able to provide a sample project that we can use to reproduce it?

Cheers,

Renato


(Yash Bhardwaj) #6

Pardon me for not posting it here, but it’s stupid mistake on the external-service that it expects the amounts in String in the request JSON, which should have been expected as double. It’s resolved as soon as I found that.

We can close it.