mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
rm unused middleware/recover
This commit is contained in:
@@ -5,8 +5,8 @@ incoming HTTP requests and produce appropriate responses.
|
||||
|
||||
The package includes middleware for security headers (SetPrivacyHeaders), error catching
|
||||
and handling (CatchError, HandleError), rate limiting (IPRateLimiter, RateLimitRequest), logging (LogRequest),
|
||||
panic recovery (RecoverFromPanic), and user context injection (ProvideUserContext). These
|
||||
middlewares can be applied to routes to add cross-cutting functionality across multiple endpoints.
|
||||
and user context injection (ProvideUserContext). These middlewares can be applied to routes to add cross-cutting
|
||||
functionality across multiple endpoints.
|
||||
|
||||
Route definitions are centralized in the DefineRoutes function, which sets up all paths
|
||||
and their corresponding handlers using the gorilla/mux router.
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RecoverFromPanic wraps an http.Handler and recovers from any panics that occur during its execution.
|
||||
// If a panic occurs, it sends an HTTP 500 Internal Server Error response with the panic message.
|
||||
func RecoverFromPanic(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var errorString string
|
||||
defer func() {
|
||||
r := recover()
|
||||
if r != nil {
|
||||
switch t := r.(type) {
|
||||
case string:
|
||||
errorString = t
|
||||
case error:
|
||||
errorString = t.Error()
|
||||
default:
|
||||
errorString = "Unknown error"
|
||||
}
|
||||
http.Error(w, errorString, http.StatusInternalServerError)
|
||||
}
|
||||
}()
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user