Add copy error messages with request id

This commit is contained in:
dwrz
2026-07-05 18:14:40 +00:00
parent 112d994113
commit 0345dab110
3 changed files with 21 additions and 6 deletions

View File

@@ -211,7 +211,6 @@ func (svc *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
slog.String("path", r.URL.Path), slog.String("path", r.URL.Path),
)) ))
) )
// Log completion time. // Log completion time.
defer func() { defer func() {
log.InfoContext( log.InfoContext(
@@ -249,6 +248,9 @@ func (svc *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.InfoContext(ctx, "handling") log.InfoContext(ctx, "handling")
// Always set request ID header.
w.Header().Set("X-Request-ID", id)
// Pass the request on to the multiplexer. // Pass the request on to the multiplexer.
svc.mux.ServeHTTP(w, r) svc.mux.ServeHTTP(w, r)
} }

View File

@@ -657,14 +657,21 @@ class Odidere {
body: JSON.stringify(payload), body: JSON.stringify(payload),
signal: this.currentController.signal, signal: this.currentController.signal,
}); });
const requestId = res.headers.get('X-Request-ID') || '';
if (!res.ok) { if (!res.ok) {
const err = await res.text(); const err = await res.text();
throw new Error(`server error ${res.status}: ${err}`); this.renderer.renderError(
`server error ${res.status}: ${err}`,
requestId,
);
return;
} }
for await (const { eventType, event } of this._parseSSEStream(res)) { for await (const { eventType, event } of this._parseSSEStream(res)) {
if (event.error) { if (event.error) {
throw new Error(event.error); this.renderer.renderError(event.error, requestId);
return;
} }
if ( if (

View File

@@ -403,11 +403,17 @@ export class Renderer {
* renderError renders an error message in the chat. * renderError renders an error message in the chat.
* @param {string} message * @param {string} message
*/ */
renderError(message) { renderError(message, requestId = '') {
const $msg = const $msg =
this.$tplErrorMessage.content.cloneNode(true).firstElementChild; this.$tplErrorMessage.content.cloneNode(true).firstElementChild;
$msg.querySelector('.message__content').textContent = message; const $content = $msg.querySelector('.message__content');
$msg.dataset.copyText = message; if (requestId) {
$content.textContent = `Request: ${requestId}\n${message}`;
$msg.dataset.copyText = `Request: ${requestId}\n${message}`;
} else {
$content.textContent = message;
$msg.dataset.copyText = message;
}
this.$chat.insertBefore($msg, this.$chatLoading); this.$chat.insertBefore($msg, this.$chatLoading);
this.scrollToBottom(); this.scrollToBottom();
} }