Skip to content

Commit

Permalink
Improved error management and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ybizeul committed Aug 30, 2023
1 parent 7669fc3 commit 964542d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
21 changes: 11 additions & 10 deletions web/ui/src/YBFeed/YBFeedComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
56 changes: 38 additions & 18 deletions web/ui/src/YBFeed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,44 @@ export class FeedConnector {
return "/api/feed/"+encodeURIComponent(feedName)
}
async GetFeed(feedName: string): Promise<Feed|null> {
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<j.items.length;i++) {
j.items[i].feed = j
}
return j
return new Promise((resolve, reject) => {
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<j.items.length;i++) {
j.items[i].feed = j
}
resolve(j)
})
})

})
}
async AuthenticateFeed(feedName: string, secret: string): Promise<boolean> {
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<boolean> {
return fetch(this.feedUrl(feedName),{
Expand All @@ -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
})
Expand Down

0 comments on commit 964542d

Please sign in to comment.