From 964542da135ef28703aa3f65379ed66e4c138d84 Mon Sep 17 00:00:00 2001 From: Yann Bizeul Date: Wed, 30 Aug 2023 15:40:16 +0200 Subject: [PATCH] Improved error management and reporting --- web/ui/src/YBFeed/YBFeedComponent.tsx | 21 +++++----- web/ui/src/YBFeed/index.ts | 56 ++++++++++++++++++--------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/web/ui/src/YBFeed/YBFeedComponent.tsx b/web/ui/src/YBFeed/YBFeedComponent.tsx index 18425b2..9ed6212 100644 --- a/web/ui/src/YBFeed/YBFeedComponent.tsx +++ b/web/ui/src/YBFeed/YBFeedComponent.tsx @@ -112,19 +112,20 @@ export function FeedComponent() { useEffect( () => { const interval = window.setInterval(update,2000) - const secret = searchParams.get("secret") if (secret) { + console.log("test") connection.AuthenticateFeed(feedParam,secret) - .then(() => { - setGoTo("/" + feedParam) - update() - }) - .catch((e) => { - console.log(e) - message.error(e.message) - setAuthenticated(false) - }) + .then(() => { + console.log("then") + setGoTo("/" + feedParam) + update() + }) + .catch((e) => { + console.log(e.message) + message.error(e.message) + setAuthenticated(false) + }) } else { update() diff --git a/web/ui/src/YBFeed/index.ts b/web/ui/src/YBFeed/index.ts index 6807b2e..c45b1fc 100644 --- a/web/ui/src/YBFeed/index.ts +++ b/web/ui/src/YBFeed/index.ts @@ -31,26 +31,44 @@ export class FeedConnector { return "/api/feed/"+encodeURIComponent(feedName) } async GetFeed(feedName: string): Promise { - var f = await fetch(this.feedUrl(feedName),{ - credentials: "include" - }) - if (f.status !== 200) { - throw new YBFeedError(f.status, f.statusText) - } - const j = await f.json() - for (var i=0;i { + fetch(this.feedUrl(feedName),{ + credentials: "include" + }) + .then((f) => { + if (f.status !== 200) { + f.text() + .then(text => { + reject(new YBFeedError(f.status, text)) + }) + } + f.json() + .then(j => { + for (var i=0;i { - var f = await fetch(this.feedUrl(feedName)+"?secret="+encodeURIComponent(secret),{ - credentials: "include" + return new Promise((resolve, reject) => { + fetch(this.feedUrl(feedName)+"?secret="+encodeURIComponent(secret),{ + credentials: "include" + }) + .then(f => { + if (f.status !== 200) { + f.text() + .then(text => { + reject(new YBFeedError(f.status, text)) + }) + } else { + resolve(true) + } + }) }) - if (f.status !== 200) { - throw new YBFeedError(f.status, f.statusText) - } - return true } async SetPIN(feedName: string, pin: string): Promise { return fetch(this.feedUrl(feedName),{ @@ -60,7 +78,9 @@ export class FeedConnector { }) .then((f) => { if (f.status !== 200) { - throw new YBFeedError(f.status, f.statusText) + f.text().then((b) => { + throw new YBFeedError(f.status, b) + }) } return true })