19 lines
		
	
	
		
			407 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			407 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package middleware
 | 
						|
 | 
						|
import (
 | 
						|
	"log/slog"
 | 
						|
	"net/http"
 | 
						|
)
 | 
						|
 | 
						|
func RecoverMiddleware(next http.Handler) http.Handler {
 | 
						|
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
						|
		defer func() {
 | 
						|
			if err := recover(); err != nil {
 | 
						|
				slog.Error("Recovered from panic", "error", err)
 | 
						|
				http.Error(w, "Internal Server Error", http.StatusInternalServerError)
 | 
						|
			}
 | 
						|
		}()
 | 
						|
		next.ServeHTTP(w, r)
 | 
						|
	})
 | 
						|
}
 |