Handling API error with a toast. Showing WROLModeMessage on more pages.

This commit is contained in:
Roland 2022-01-15 18:15:23 -07:00
parent 474e68cc3d
commit 6c5533a775
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 18 additions and 16 deletions

View file

@ -33,7 +33,8 @@ async function apiCall(url, method, body, ms = 10000) {
try {
// await the response or error.
let response = await timeoutPromise(ms, promise);
if (response.status === 403 && (await response.json())['code'] === 17) {
let copy = response.clone();
if (response.status === 403 && (await copy.json())['code'] === 17) {
toast({
type: 'error',
title: 'WROL Mode is enabled!',
@ -134,16 +135,6 @@ export async function getVideo(video_id) {
export async function deleteVideo(video_id) {
let response = await apiDelete(`${VIDEOS_API}/video/${video_id}`);
let data = await response.json();
if (data.code === 17) {
toast({
type: 'warning',
title: 'WROL Mode Enabled',
description: 'This cannot be done while WROL Mode is enabled.',
time: 5000,
});
throw Error('WROL Mode enabled');
}
if (response.status !== 204) {
toast({
type: 'error',
@ -151,7 +142,6 @@ export async function deleteVideo(video_id) {
description: 'Failed to delete video. See server logs.',
time: 5000,
});
throw Error('Failed to delete video');
}
}
@ -328,7 +318,12 @@ export async function searchArchives(offset, limit, domain = null, searchStr = n
let data = await response.json();
return [data['archives'], data['totals']['archives']];
} else {
throw Error(`Unable to search archives`);
toast({
type: 'error',
title: 'Unable to search archives',
description: 'Cannot search archives. See server logs.',
time: 5000,
});
}
}
@ -342,7 +337,12 @@ export async function fetchDomains() {
let data = await response.json();
return [data['domains'], data['totals']['domains']];
} else {
throw Error(`Unable to fetch domains`);
toast({
type: 'error',
title: 'Domains Error',
description: 'Unable to fetch Domains. See server logs.',
time: 5000,
});
}
}

View file

@ -1,6 +1,6 @@
import React, {useState} from "react";
import {Card, Confirm, Container, Icon, Image, Placeholder, Tab} from "semantic-ui-react";
import Paginator, {ClearButton, ExternalLink, SearchInput, textEllipsis, uploadDate} from "./Common";
import Paginator, {ClearButton, ExternalLink, SearchInput, textEllipsis, uploadDate, WROLModeMessage} from "./Common";
import {deleteArchive, postDownload, refreshArchives} from "../api";
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
import {Link, NavLink} from "react-router-dom";
@ -226,6 +226,7 @@ class ManageArchives extends React.Component {
render() {
return (<>
<WROLModeMessage content='Cannot modify Archives'/>
<Button secondary
onClick={this.refresh}>
Refresh Archive Files

View file

@ -11,7 +11,7 @@ import Paginator, {
searchOrders,
secondsToString,
VideoCards,
videoOrders
videoOrders, WROLModeMessage
} from "./Common"
import VideoPage from "./VideoPlayer";
import {download, getChannel, getStatistics, getVideo, refresh, searchVideos} from "../api";
@ -64,6 +64,7 @@ class ManageVideos extends React.Component {
render() {
return (
<Container fluid>
<WROLModeMessage content='Cannot modify Videos'/>
<Header as="h1">Manage Videos</Header>
<p>