When you have a logging middleware, any 5xx error raised by the server are responded like that for security reasons. The client only receives an "internal server error", and the real error is logged as a trace message. Make sure you log trace messages to some place (like a text file) to see what the message refers to.
I'm not sure it can be more elegant than this. What is your suggestion?
The internal error is really an "internal" error. It's an unhandled error at your side. It's usually not safe to tell the customer what it is. Might be a wrong SQL, disk issues, whatever. It also really depends on the moment of the error. It's not clear here when does it happen.