Skip to content

Commit 9a9fa67

Browse files
committed
Improved error messages for incorrect content
1 parent e77a157 commit 9a9fa67

File tree

2 files changed

+100
-14
lines changed

2 files changed

+100
-14
lines changed

src/views/products/ContentService.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export interface IContentService extends ObservableService<ContentServiceEvent>
9898
*/
9999
export class ContentService {
100100

101+
/**
102+
*
103+
* @private
104+
*/
105+
private static _retryFailedLoadTimeout : number | NodeJS.Timeout | undefined = undefined;
106+
101107
private static _state : ContentServiceState = ContentServiceState.UNINITIALIZED;
102108
private static _productChangedListeners: ObservableListener<ContentServiceEvent.PRODUCTS_CHANGED>[] = [];
103109
private static _currentProducts : readonly string[] = [];
@@ -280,7 +286,11 @@ export class ContentService {
280286
// Schedule failed tasks for retry
281287
if (failed.length > 0) {
282288
console.log('Scheduling retry for failed products: ', failed);
283-
setTimeout(() => {
289+
if (this._retryFailedLoadTimeout !== undefined) {
290+
clearTimeout(this._retryFailedLoadTimeout);
291+
this._retryFailedLoadTimeout = undefined;
292+
}
293+
this._retryFailedLoadTimeout = setTimeout(() => {
284294
console.warn('Retrying failed products: ', failed);
285295
this._loadProductsByNames(failed).catch(err => {
286296
console.error('Error loading failed products: ', err);

src/views/products/hooks/useContentView.ts

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,102 @@ export function useContentView (serviceName : string, viewName : string) {
5757
return view;
5858
}
5959

60-
function createProductNotFound (viewName: string) : ViewContent {
61-
return {
62-
name: viewName,
63-
type: ContentType.VIEW,
64-
body: `Product not found: ${viewName}`
65-
};
60+
function createLoadingView (viewName: string) : ViewContent {
61+
return createCardView(viewName, `Loading: ${viewName}`, "Please wait while we load the content.");
6662
}
6763

68-
function createLoadingView (viewName: string) : ViewContent {
69-
return {
70-
name: viewName,
71-
type: ContentType.VIEW,
72-
body: `Loading: ${viewName}`
73-
};
64+
function createProductNotFound (viewName: string) : ViewContent {
65+
return createCardView(viewName, `${viewName}`, "The product you are looking for could not be found. Please try again later.");
7466
}
7567

7668
function createViewNotFound (viewName: string) : ViewContent {
69+
return createCardView(viewName, `${viewName}`, "The product you are looking for could not be found. Please try again later.");
70+
}
71+
72+
function createCardView (
73+
viewName: string,
74+
title: string,
75+
message: string,
76+
) : ViewContent {
7777
return {
7878
name: viewName,
7979
type: ContentType.VIEW,
80-
body: `View not found: ${viewName}`
80+
body: [
81+
{
82+
type: ContentType.DIV,
83+
classes: [
84+
"cards-container",
85+
"flex",
86+
"flex-col",
87+
"items-center",
88+
"justify-center",
89+
"mx-2",
90+
"h-[calc(100vh",
91+
"-",
92+
"4rem)]",
93+
"md:px-[20%]",
94+
"lg:px-[32%]",
95+
],
96+
body: [
97+
{
98+
type: ContentType.DIV,
99+
classes: [
100+
"flex",
101+
"flex-col",
102+
"items-center",
103+
"justify-center",
104+
"bg-backgroundLight",
105+
"rounded-lg",
106+
"w-full",
107+
"max-w-full",
108+
"mb-5",
109+
"overflow-hidden",
110+
"prose",
111+
"prose-white",
112+
],
113+
body: [
114+
{
115+
type: ContentType.DIV,
116+
classes: [
117+
"flex",
118+
"flex-col",
119+
"items-center",
120+
"justify-center",
121+
"bg-backgroundLight",
122+
"rounded-lg",
123+
"w-full",
124+
"max-w-full",
125+
"mb-5",
126+
"overflow-hidden",
127+
"prose",
128+
"prose-white",
129+
],
130+
body: [
131+
{
132+
type: ContentType.H3,
133+
classes: [
134+
"text-xl",
135+
"font-bold",
136+
"mt-1",
137+
"mb-1"
138+
],
139+
body: title,
140+
},
141+
{
142+
type: ContentType.P,
143+
classes: [
144+
"text-center",
145+
"ml-2",
146+
"mr-2",
147+
],
148+
body: message
149+
}
150+
]
151+
}
152+
]
153+
}
154+
]
155+
}
156+
]
81157
};
82158
}

0 commit comments

Comments
 (0)