1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-09-08 17:06:42 +00:00

improve error messages

This commit is contained in:
Laura
2025-08-11 01:21:05 +02:00
parent 28997fa8e1
commit 84aee7ae76
3 changed files with 12 additions and 3 deletions

View File

@@ -128,7 +128,7 @@ func HandleChat(w http.ResponseWriter, r *http.Request) {
stream, err := OpenRouterStartStream(ctx, *request)
if err != nil {
RespondJson(w, http.StatusBadRequest, map[string]any{
"error": err.Error(),
"error": GetErrorMessage(err),
})
return

View File

@@ -253,7 +253,6 @@
#render(only = false, noScroll = false) {
if (!only || only === "tags") {
console.log(this.#tags);
this.#_tags.innerHTML = this.#tags
.map((tag) => `<div class="tag-${tag}" title="${tag}"></div>`)
.join("");

View File

@@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"net/http"
"github.com/revrost/go-openrouter"
)
type Chunk struct {
@@ -65,6 +67,14 @@ func TextChunk(text string) Chunk {
func ErrorChunk(err error) Chunk {
return Chunk{
Type: "error",
Text: err.Error(),
Text: GetErrorMessage(err),
}
}
func GetErrorMessage(err error) string {
if apiErr, ok := err.(*openrouter.APIError); ok {
return apiErr.Error()
}
return err.Error()
}