diff options
| author | Bobby <[email protected]> | 2026-03-08 05:43:04 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-08 05:43:04 +0530 |
| commit | 662dd2069dc8590e8b54823a33726464cf10c4e7 (patch) | |
| tree | 55a740e6114440d7e311afd3f5ba79a7101965f8 /utils/shortcuts/error.go | |
| parent | d21ea918864a8b18fef94bbfaec8097444be1b17 (diff) | |
| download | dove-662dd2069dc8590e8b54823a33726464cf10c4e7.tar.xz dove-662dd2069dc8590e8b54823a33726464cf10c4e7.zip | |
feat(domains): enhance TLD and domain management with edit and delete functionality
- Added edit and delete buttons for TLDs in the TLD management interface.
- Implemented a modal confirmation for delete actions across TLDs, mailboxes, users, and aliases.
- Created separate edit pages for domains and TLDs with forms for updating their details.
- Improved user experience by adding alerts for error messages and success notifications.
feat(mail): streamline mailbox management with alias support
- Introduced alias creation and deletion functionality for mailboxes.
- Enhanced mailbox edit interface to include alias management.
- Added dropdowns for selecting users and domains when creating aliases.
fix(alerts): implement alert system for error messages
- Developed a reusable alert component to display error messages.
- Integrated alert dismiss functionality with automatic timeout for user notifications.
refactor: general code improvements and organization
- Updated error handling in the backend to support HTMX requests.
- Refactored redirect functions to handle HTMX redirects appropriately.
Diffstat (limited to 'utils/shortcuts/error.go')
| -rw-r--r-- | utils/shortcuts/error.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/utils/shortcuts/error.go b/utils/shortcuts/error.go index c22e6b2..ae6cec3 100644 --- a/utils/shortcuts/error.go +++ b/utils/shortcuts/error.go @@ -38,42 +38,77 @@ func ServiceError(kind ErrorKind, message string) *Error { } } +func isHtmxRequest(context *fiber.Ctx) bool { + return context.Get("HX-Request") == "true" && context.Get("HX-Boosted") != "true" +} + +func renderAlert(context *fiber.Ctx, message string, statusCode int) error { + context.Status(statusCode) + return context.Render("partials/alert", fiber.Map{ + "ErrorMessage": message, + }) +} + func HandleError(context *fiber.Ctx, serviceError *Error) error { statusCode, exists := statusMap[serviceError.Kind] if !exists { statusCode = fiber.StatusInternalServerError } + if isHtmxRequest(context) { + return renderAlert(context, serviceError.Message, statusCode) + } + return RenderWithStatus(context, "error", fiber.Map{ "ErrorMessage": serviceError.Message, }, statusCode) } func BadRequestError(context *fiber.Ctx, err error) error { + if isHtmxRequest(context) { + return renderAlert(context, err.Error(), fiber.StatusBadRequest) + } + return RenderWithStatus(context, "error", fiber.Map{ "ErrorMessage": err.Error(), }, fiber.StatusBadRequest) } func ForbiddenError(context *fiber.Ctx, err error) error { + if isHtmxRequest(context) { + return renderAlert(context, err.Error(), fiber.StatusForbidden) + } + return RenderWithStatus(context, "error", fiber.Map{ "ErrorMessage": err.Error(), }, fiber.StatusForbidden) } func InternalServerError(context *fiber.Ctx, err error) error { + if isHtmxRequest(context) { + return renderAlert(context, err.Error(), fiber.StatusInternalServerError) + } + return RenderWithStatus(context, "error", fiber.Map{ "ErrorMessage": err.Error(), }, fiber.StatusInternalServerError) } func NotFoundError(context *fiber.Ctx, err error) error { + if isHtmxRequest(context) { + return renderAlert(context, err.Error(), fiber.StatusNotFound) + } + return RenderWithStatus(context, "error", fiber.Map{ "ErrorMessage": err.Error(), }, fiber.StatusNotFound) } func UnauthorizedError(context *fiber.Ctx, err error) error { + if isHtmxRequest(context) { + return renderAlert(context, err.Error(), fiber.StatusUnauthorized) + } + return RenderWithStatus(context, "error", fiber.Map{ "ErrorMessage": err.Error(), }, fiber.StatusUnauthorized) |
