Skip to content

Surface htmx errors in admin UI#16

Merged
dzarlax merged 1 commit into
mainfrom
codex/admin-htmx-error-surface
Jun 16, 2026
Merged

Surface htmx errors in admin UI#16
dzarlax merged 1 commit into
mainfrom
codex/admin-htmx-error-surface

Conversation

@dzarlax

@dzarlax dzarlax commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • handle htmx 4xx/5xx responses in the admin layout and show an inline error instead of leaving only a console error
  • keep server-side status codes unchanged for raw requests

Tests

  • go test -count=1 ./...

Summary by CodeRabbit

  • New Features
    • Improved user experience in the admin interface with automatic inline error message display for asynchronous operations. Styled error alerts now appear immediately when operations fail, providing users with clear visual feedback and better context to understand any issues encountered.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 23ac3485-3d42-48ac-bd18-af6cb2be56a6

📥 Commits

Reviewing files that changed from the base of the PR and between cb67c34 and 8a7a8d3.

📒 Files selected for processing (1)
  • internal/adminapi/templates/partials_layout.html

📝 Walkthrough

Walkthrough

A single template file gains a htmx:beforeSwap JavaScript event listener that intercepts HTTP error responses (status ≥ 400), prevents the default swap, removes any existing inline error alert from the host container, and inserts a new alert with the response text or a fallback status message. A matching .admin-inline-error CSS rule is added for visual styling.

Changes

HTMX Inline Error Display

Layer / File(s) Summary
Inline error handler and styles
internal/adminapi/templates/partials_layout.html
Adds a htmx:beforeSwap listener in admin_head that suppresses swaps on status ≥ 400, clears prior .admin-inline-error elements, and prepends a new alert with the trimmed response text or HTTP status fallback. Adds the .admin-inline-error CSS rule with warning background/text colors, spacing, padding, border radius, and font size.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 Hippity-hop, an error appears,
Before the swap lands, the rabbit interferes!
.admin-inline-error glows yellow and bright,
With padding and radius, the warning looks right.
No more silent failures — the UI is clear! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: adding error display functionality for htmx requests in the admin UI, matching the core objective of the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/admin-htmx-error-surface

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a7a8d3bc7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

document.addEventListener("htmx:beforeSwap", function (event) {
var detail = event.detail || {};
var xhr = detail.xhr;
if (!xhr || xhr.status < 400) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear stale inline errors after successful retries

Because this handler returns before finding/removing any existing .admin-inline-error for all <400 responses, a transient htmx failure can leave a stale alert after the user retries successfully. For example, the Refresh catalog button in internal/adminapi/templates/index.html swaps only #models-content, while this handler prepends the error to the surrounding .card__body; a successful retry replaces #models-content but never removes that sibling alert, so the UI continues to show the old failure. Clear the host's prior error before this return or on successful swap.

Useful? React with 👍 / 👎.

@dzarlax dzarlax merged commit 9800357 into main Jun 16, 2026
6 checks passed
@dzarlax dzarlax deleted the codex/admin-htmx-error-surface branch June 16, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant