Skip to content

Commit

Permalink
add: model-provider errors
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Dec 23, 2024
1 parent a140cbd commit 6c75635
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
18 changes: 17 additions & 1 deletion pkg/controller/handlers/toolreference/toolreference.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package toolreference
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"net/url"
"os"
"path"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -385,7 +387,21 @@ func (h *Handler) BackPopulateModels(req router.Request, _ router.Response) erro
if err != nil {
// Don't error and retry because it will likely fail again. Log the error, and the user can re-sync manually.
// Also, the toolRef.Status.Error field will bubble up to the user in the UI.
toolRef.Status.Error = err.Error()

// Check if the model provider returned a properly formatted error message and set it as status
re := regexp.MustCompile(`\{.*"error":.*}`)
match := re.FindString(err.Error())
if match != "" {
toolRef.Status.Error = match
type errorResponse struct {
Error string `json:"error"`
}
var eR errorResponse
if err := json.Unmarshal([]byte(match), &eR); err == nil {
toolRef.Status.Error = eR.Error
}
}

log.Errorf(err.Error())

Check failure on line 405 in pkg/controller/handlers/toolreference/toolreference.go

View workflow job for this annotation

GitHub Actions / lint

printf: non-constant format string in call to (*github.com/obot-platform/obot/logger.Logger).Errorf (govet)
return nil
}
Expand Down
10 changes: 9 additions & 1 deletion ui/admin/app/components/model-providers/ModelProviderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ export function ModelProviderForm({
<AlertDescription>
Your configuration was saved, but we were not able
to connect to the model provider. Please check your
configuration and try again.
configuration and try again:{" "}
<strong>
{(typeof fetchAvailableModels.error ===
"object" &&
"message" in fetchAvailableModels.error &&
(fetchAvailableModels.error
.message as string)) ??
"Unknown error"}
</strong>
</AlertDescription>
</Alert>
</div>
Expand Down
14 changes: 14 additions & 0 deletions ui/admin/app/hooks/useAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ export function useAsync<TData, TParams extends unknown[]>(
onSuccess?.(data, params);
})
.catch((error) => {
if (
error.response &&
typeof error.response.data === "string"
) {
const errorMessageMatch =
error.response.data.match(/{"error":"(.*?)"}/);
if (errorMessageMatch) {
const errorMessage = JSON.parse(
errorMessageMatch[0]
).error;
console.log("Error: ", errorMessage);
error.message = errorMessage;
}
}
setError(error);
onError?.(error, params);
})
Expand Down

0 comments on commit 6c75635

Please sign in to comment.