I get an error "Internal Server error"

I tried this code:

implicit val customServerOptions: AkkaHttpServerOptions =
    AkkaHttpServerOptions.customiseInterceptors
      .decodeFailureHandler(ctx => {
                logger.error(s"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
                ctx.failingInput match {
                  // when defining how a decode failure should be handled, we need
                  // to describe the output to be used, and
                  // a value for this output
                  case _: EndpointIO.Body[_, _] =>
                    // see this function and then to failureSourceMessage function
                    // to find out which types of decode errors are present
                    val failureMessage = FailureMessages.failureMessage(ctx)
                    logger.error(s"$failureMessage")
                    // warning - log working incorrect when there are several endpoints
                    // with different methods
                    DefaultDecodeFailureHandler.default(ctx)
                  case _ =>
                    logger.error("##########################")
                    DefaultDecodeFailureHandler.default(ctx)
                }
      })
      .exceptionHandler(ExceptionHandler[Future] { ctx =>
              logger.error("##########################################")
              // defining exception id for the exception to make search in logs easier.
              val exceptionId = UUID.randomUUID()
              logger.error(s"Intercepted exception ${ctx.e} while processing request, " +
                        "exception id: $exceptionId")
              Future.successful(Some(ValuedEndpointOutput[ErrorMessage](jsonBody[ErrorMessage],
                        ErrorMessage(s"Internal Server Error, exception id: $exceptionId"))))
      })
      .options

  // converting an endpoint to a route (providing server-side logic); extension method comes from imported packages
    val tapirRoutes: akka.http.scaladsl.server.Route =
                    AkkaHttpServerInterpreter(customServerOptions)

Doesn´t show anything else,

What else can I do ?

A few questions:

  1. Does error 500 happen on a particular endpoint, while other endpoints are working? Could you show the endpoint definition?
  2. Does your logging configuration work in other cases? I’m asking just to make sure it’s not the case Akka logging is misconfigured.
  3. What’s the security handling in the failing endpoint, if any?
1 Like

1.-Does error 500 happen on a particular endpoint, while other endpoints are working? Could you show the endpoint definition?

Yes, one in particular i am trying to do something like a microservice, just making another project to test if it is better to separate some searches in postgresql.

I found the problem in the main project i had a ‘case class’ with a field’s name differente from.the other project.

But I want a better logging, :slight_smile:

2.-Does your logging configuration work in other cases? I’m asking just to make sure it’s not the case Akka logging is misconfigured.

I have not tested in another.

3.-What’s the security handling in the failing endpoint, if any

I have no security handling

Thank you

I tried to replicate your case, but so far I can’t get to a similar state. Here’s a gist based on the Akka HTTP example and your server options: TapirAkkaDecodingLogging · GitHub

As expected, it returns HTTP 400 with a meaningful error if JSON decoding fails. It also uses the custom DecodeFailureHandler and does the additional logging to stdout. I tried to break the input JSON in various ways, but it never results in HTTP 500 with a silent exception.

Could you specify what’s the endpoint input and output type? Are streams involved?