Skip to content

Commit

Permalink
feat: commented out breaking code
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Dec 16, 2024
1 parent fe36d90 commit 7c1fbe0
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,35 @@ func getFromAuth(path string) (*extractResponse, error) {
}

// Middleware to handle InternalServerError
func internalServerErrorHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rr := &responseRecorder{ResponseWriter: w, statusCode: http.StatusOK}
next.ServeHTTP(rr, r)

if rr.statusCode == http.StatusInternalServerError {
fmt.Printf("Internal Server Error: %s %s\n", r.Method, r.URL.Path)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
}
// func internalServerErrorHandler(next http.Handler) http.Handler {
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// rr := &responseRecorder{ResponseWriter: w, statusCode: http.StatusOK}
// next.ServeHTTP(rr, r)

// if rr.statusCode == http.StatusInternalServerError {
// fmt.Printf("Internal Server Error: %s %s\n", r.Method, r.URL.Path)
// http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
// }
// })
// }

// Custom ResponseWriter to capture status codes
type responseRecorder struct {
http.ResponseWriter
statusCode int
}
// type responseRecorder struct {
// http.ResponseWriter
// statusCode int
// }

func (rr *responseRecorder) WriteHeader(code int) {
rr.statusCode = code
rr.ResponseWriter.WriteHeader(code)
}
// func (rr *responseRecorder) WriteHeader(code int) {
// rr.statusCode = code
// rr.ResponseWriter.WriteHeader(code)
// }

func initChi() *chi.Mux {
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(internalServerErrorHandler)
// r.Use(internalServerErrorHandler)
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
Expand Down

0 comments on commit 7c1fbe0

Please sign in to comment.