Skip to content

hossensyedriadh/spring-pretty-exception

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pretty Exception – Spring Boot Starter

A lightweight Spring Boot starter that replaces the default white-label error page with a clean, readable, developer-friendly exception view. It highlights the exact source line where the exception occurred and displays detailed request, environment, and system info — all in one page.

✨ Features:

  • Pretty HTML exception page using Thymeleaf
  • Automatic source-code extraction with highlight.js
  • Highlights the exact line that triggered the exception
  • Displays full request details (headers, params, origin, user-agent, etc.)
  • Shows Java version Spring Boot version, Spring Active profiles, OS information
  • Enabled automatically only when:
    • The application is a Servlet web app
    • The JAR is not deployed as a WAR
    • The property pretty-exception.enabled=true

🖥️ How It Works

  • The starter auto-registers a custom HandlerExceptionResolver that:
  • Captures uncaught exceptions
  • Extracts the file and line where the exception occurred
  • Reads the source file safely
  • Sends a rich model containing:
  • Exception details
  • Extracted source code
  • Request info
  • Headers, params
  • System + environment details
  • Renders a detailed HTML page via Thymeleaf

🧪 Development Notes

  • Starter automatically hooks into Spring Boot auto-configuration
  • Uses @ConditionalOnProperty to turn feature on/off
  • Uses @ConditionalOnWebApplication to avoid triggering in non-web apps
  • Works with Spring Boot 2.7+
  • Servlet-only (not reactive)