Skip to content

Commit 04a3d8e

Browse files
authored
feat(ui): add error page to display errors (#5418)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 9af09b3 commit 04a3d8e

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

core/http/endpoints/localai/gallery.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (mgs *ModelGalleryEndpointService) ListModelFromGalleryEndpoint() func(c *f
120120

121121
models, err := gallery.AvailableGalleryModels(mgs.galleries, mgs.modelPath)
122122
if err != nil {
123+
log.Error().Err(err).Msg("could not list models from galleries")
123124
return err
124125
}
125126

core/http/routes/ui.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,17 @@ func RegisterUIRoutes(app *fiber.App,
131131
page := c.Query("page")
132132
items := c.Query("items")
133133

134-
models, _ := gallery.AvailableGalleryModels(appConfig.Galleries, appConfig.ModelPath)
134+
models, err := gallery.AvailableGalleryModels(appConfig.Galleries, appConfig.ModelPath)
135+
if err != nil {
136+
log.Error().Err(err).Msg("could not list models from galleries")
137+
return c.Status(fiber.StatusInternalServerError).Render("views/error", fiber.Map{
138+
"Title": "LocalAI - Models",
139+
"BaseURL": utils.BaseURL(c),
140+
"Version": internal.PrintableVersion(),
141+
"ErrorCode": "500",
142+
"ErrorMessage": err.Error(),
143+
})
144+
}
135145

136146
// Get all available tags
137147
allTags := map[string]struct{}{}

core/http/views/error.html

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
{{template "views/partials/head" .}}
4+
5+
<body class="bg-gradient-to-br from-gray-900 to-gray-950 text-gray-200">
6+
<div class="flex flex-col min-h-screen">
7+
8+
{{template "views/partials/navbar" .}}
9+
10+
<div class="container mx-auto px-4 py-8 flex-grow">
11+
<!-- Error Section -->
12+
<div class="bg-gradient-to-r from-blue-900/30 to-indigo-900/30 rounded-2xl shadow-xl p-8 mb-10">
13+
<div class="max-w-4xl mx-auto text-center">
14+
<div class="mb-6 text-6xl text-blue-400">
15+
<i class="fas fa-exclamation-circle"></i>
16+
</div>
17+
<h1 class="text-4xl md:text-5xl font-bold text-white mb-4">
18+
<span class="bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-indigo-400">
19+
{{if .ErrorCode}}{{.ErrorCode}}{{else}}Error{{end}}
20+
</span>
21+
</h1>
22+
<p class="text-xl text-gray-300 mb-6">{{if .ErrorMessage}}{{.ErrorMessage}}{{else}}An unexpected error occurred{{end}}</p>
23+
<div class="flex flex-wrap justify-center gap-4">
24+
<a href="./"
25+
class="group flex items-center bg-blue-600 hover:bg-blue-700 text-white py-2 px-6 rounded-lg transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg">
26+
<i class="fas fa-home mr-2"></i>
27+
<span>Return Home</span>
28+
<i class="fas fa-arrow-right opacity-0 group-hover:opacity-100 group-hover:translate-x-2 ml-2 transition-all duration-300"></i>
29+
</a>
30+
<a href="browse"
31+
class="group flex items-center bg-indigo-600 hover:bg-indigo-700 text-white py-2 px-6 rounded-lg transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg">
32+
<i class="fas fa-images mr-2"></i>
33+
<span>Browse Gallery</span>
34+
<i class="fas fa-arrow-right opacity-0 group-hover:opacity-100 group-hover:translate-x-2 ml-2 transition-all duration-300"></i>
35+
</a>
36+
</div>
37+
</div>
38+
</div>
39+
40+
<!-- Additional Information -->
41+
<div class="bg-gray-800/50 border border-gray-700/50 rounded-xl p-8 shadow-md backdrop-blur-sm">
42+
<div class="text-center max-w-3xl mx-auto">
43+
<div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-yellow-500/20 mb-4">
44+
<i class="text-yellow-400 text-2xl fa-solid fa-triangle-exclamation"></i>
45+
</div>
46+
<h2 class="text-2xl md:text-3xl font-semibold text-gray-100 mb-4">Need help?</h2>
47+
<p class="text-lg text-gray-300 mb-6">Visit our <a class="text-blue-400 hover:text-blue-300 underline underline-offset-2" href="browse">🖼️ Gallery</a> or check the <a href="https://localai.io/basics/getting_started/" class="text-blue-400 hover:text-blue-300 underline underline-offset-2"> <i class="fa-solid fa-book"></i> Getting started documentation</a></p>
48+
</div>
49+
</div>
50+
</div>
51+
52+
{{template "views/partials/footer" .}}
53+
</div>
54+
55+
</body>
56+
</html>

0 commit comments

Comments
 (0)