func handleRequest(ctx *Context) { if !isValidRequest(ctx) { ctx.RespondWithErrorMessage(http.StatusBadRequest, "Invalid request") return } // ...other logic }
func handleUserError(ctx *Context) { err := someFuncThatReturnsAnError() if err != nil { ctx.RespondWithErrorMessage(http.StatusBadRequest, err.Error()) return } // ...other logic }
func handleServerError(ctx *Context) { err := someFuncThatReturnsAnError() if err != nil { ctx.RespondWithErrorMessage(http.StatusInternalServerError, "Internal server error") log.Printf("Error processing request: %v", err) return } // ...other logic }This example shows how to use "RespondWithErrorMessage" to send an HTTP 500 Internal Server Error response with a static error message when there is an error processing the request. It also logs the error to help with debugging.