diff --git a/chat.go b/chat.go index 1af4191..825497c 100644 --- a/chat.go +++ b/chat.go @@ -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 diff --git a/static/js/chat.js b/static/js/chat.js index 0c7720a..bc9fdca 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -253,7 +253,6 @@ #render(only = false, noScroll = false) { if (!only || only === "tags") { - console.log(this.#tags); this.#_tags.innerHTML = this.#tags .map((tag) => `
`) .join(""); diff --git a/stream.go b/stream.go index d970ee7..eba0e35 100644 --- a/stream.go +++ b/stream.go @@ -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() +}