mirror of
https://github.com/coalaura/whiskr.git
synced 2025-09-09 09:19:54 +00:00
improve error messages
This commit is contained in:
2
chat.go
2
chat.go
@@ -128,7 +128,7 @@ func HandleChat(w http.ResponseWriter, r *http.Request) {
|
|||||||
stream, err := OpenRouterStartStream(ctx, *request)
|
stream, err := OpenRouterStartStream(ctx, *request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
RespondJson(w, http.StatusBadRequest, map[string]any{
|
RespondJson(w, http.StatusBadRequest, map[string]any{
|
||||||
"error": err.Error(),
|
"error": GetErrorMessage(err),
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@@ -253,7 +253,6 @@
|
|||||||
|
|
||||||
#render(only = false, noScroll = false) {
|
#render(only = false, noScroll = false) {
|
||||||
if (!only || only === "tags") {
|
if (!only || only === "tags") {
|
||||||
console.log(this.#tags);
|
|
||||||
this.#_tags.innerHTML = this.#tags
|
this.#_tags.innerHTML = this.#tags
|
||||||
.map((tag) => `<div class="tag-${tag}" title="${tag}"></div>`)
|
.map((tag) => `<div class="tag-${tag}" title="${tag}"></div>`)
|
||||||
.join("");
|
.join("");
|
||||||
|
12
stream.go
12
stream.go
@@ -4,6 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/revrost/go-openrouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
@@ -65,6 +67,14 @@ func TextChunk(text string) Chunk {
|
|||||||
func ErrorChunk(err error) Chunk {
|
func ErrorChunk(err error) Chunk {
|
||||||
return Chunk{
|
return Chunk{
|
||||||
Type: "error",
|
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()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user