Fix: decompres before notify
This commit is contained in:
12
bot.go
12
bot.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -495,6 +496,17 @@ func monitorModelLoad(modelID string) {
|
||||
|
||||
// extractDetailedErrorFromBytes extracts detailed error information from response body bytes
|
||||
func extractDetailedErrorFromBytes(body []byte, statusCode int) string {
|
||||
// Try to decompress gzip if the response is compressed
|
||||
if len(body) >= 2 && body[0] == 0x1f && body[1] == 0x8b {
|
||||
reader, err := gzip.NewReader(bytes.NewReader(body))
|
||||
if err == nil {
|
||||
decompressed, err := io.ReadAll(reader)
|
||||
reader.Close()
|
||||
if err == nil {
|
||||
body = decompressed
|
||||
}
|
||||
}
|
||||
}
|
||||
// Try to parse as JSON to extract detailed error information
|
||||
var errorResponse map[string]any
|
||||
if err := json.Unmarshal(body, &errorResponse); err == nil {
|
||||
|
||||
13
session.go
13
session.go
@@ -170,6 +170,17 @@ func copyToClipboard(text string) error {
|
||||
}
|
||||
|
||||
func notifyUser(topic, message string) error {
|
||||
cmd := exec.Command("notify-send", topic, message)
|
||||
// Sanitize message to remove control characters that notify-send doesn't handle
|
||||
sanitized := strings.Map(func(r rune) rune {
|
||||
if r < 32 && r != '\t' {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}, message)
|
||||
// Truncate if too long
|
||||
if len(sanitized) > 200 {
|
||||
sanitized = sanitized[:197] + "..."
|
||||
}
|
||||
cmd := exec.Command("notify-send", topic, sanitized)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user