LogoTurboGo
Middleware

Recovery

Panic recovery middleware to prevent server crashes in TurboGo.

Recovery Middleware

TurboGo includes a built-in recovery handler to catch unexpected panics and prevent application crashes.


Basic Usage

app.Use(
  middleware.Recover(),
)

How It Works

  • Wraps each request in a defer-recover block.
  • If a panic occurs, it:
    • Logs the error and stack trace
    • Returns a safe 500 JSON error response

Example Error Response

{
  "error": "internal server error",
  "message": "an unexpected error occurred"
}

And console logs:

[RECOVER] Panic recovered: runtime error: invalid memory address
[RECOVER] Stack trace:
...

Use Cases

  • Prevent app crashes from unhandled errors
  • Debugging unexpected runtime issues
  • Safer request handling in production