mirror of
https://github.com/zoriya/flood.git
synced 2026-05-29 18:04:10 +00:00
server: services: refrain from using unnecessary throws
This commit is contained in:
@@ -35,11 +35,11 @@ class FeedService extends BaseService {
|
||||
*/
|
||||
async addFeed({url, label, interval}: AddFeedOptions): Promise<Feed> {
|
||||
if (typeof url !== 'string' || typeof label !== 'string' || typeof interval !== 'number') {
|
||||
throw new Error('Unprocessable Entity');
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
if (this.db == null) {
|
||||
throw new Error('');
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
const newFeed = await new Promise<Feed>((resolve, reject) => {
|
||||
@@ -67,21 +67,21 @@ class FeedService extends BaseService {
|
||||
*/
|
||||
async modifyFeed(id: string, {url, label, interval}: ModifyFeedOptions): Promise<void> {
|
||||
if (url != null && typeof url !== 'string') {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
if (label != null && typeof label !== 'string') {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
if (interval != null && typeof interval !== 'number') {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
const modifiedFeedReader = this.feedReaders.find((feedReader) => feedReader.getOptions().feedID === id);
|
||||
|
||||
if (modifiedFeedReader == null || this.db == null) {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
// JSON.parse(JSON.stringify()) to remove undefined properties
|
||||
@@ -132,7 +132,7 @@ class FeedService extends BaseService {
|
||||
|
||||
async getAll(): Promise<{feeds: Array<Feed>; rules: Array<Rule>}> {
|
||||
if (this.db == null) {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return new Promise<{feeds: Array<Feed>; rules: Array<Rule>}>((resolve, reject) => {
|
||||
@@ -179,7 +179,7 @@ class FeedService extends BaseService {
|
||||
const selectedFeedReader = this.feedReaders.find((feedReader) => feedReader.getOptions().feedID === id);
|
||||
|
||||
if (selectedFeedReader == null) {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
const items = selectedFeedReader.getItems();
|
||||
|
||||
@@ -385,7 +385,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
|
||||
|
||||
async testGateway(clientSettings?: ClientConnectionSettings): Promise<void> {
|
||||
if (clientSettings != null && clientSettings.client !== 'qBittorrent') {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return this.clientRequestManager
|
||||
|
||||
@@ -64,7 +64,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
|
||||
start,
|
||||
}: AddTorrentByFileOptions): Promise<void> {
|
||||
if (!Array.isArray(files)) {
|
||||
throw new Error();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
const torrentPaths = await Promise.all(
|
||||
@@ -249,16 +249,14 @@ class RTorrentClientGatewayService extends ClientGatewayService {
|
||||
return accumulator;
|
||||
}, []);
|
||||
|
||||
await this.stopTorrents({hashes}).catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
|
||||
await this.clientRequestManager
|
||||
.methodCall('system.multicall', [methodCalls])
|
||||
.then(this.processClientRequestSuccess, this.processClientRequestError)
|
||||
.catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
try {
|
||||
await this.stopTorrents({hashes});
|
||||
await this.clientRequestManager
|
||||
.methodCall('system.multicall', [methodCalls])
|
||||
.then(this.processClientRequestSuccess, this.processClientRequestError);
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
|
||||
if (moveFiles) {
|
||||
hashes.forEach((hash) => {
|
||||
@@ -266,7 +264,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
|
||||
const baseFileName = this.services?.torrentService.getTorrent(hash).baseFilename;
|
||||
|
||||
if (sourceBasePath == null || baseFileName == null) {
|
||||
throw new Error();
|
||||
return;
|
||||
}
|
||||
|
||||
const destinationFilePath = path.join(destination, baseFileName);
|
||||
@@ -282,9 +280,11 @@ class RTorrentClientGatewayService extends ClientGatewayService {
|
||||
}
|
||||
|
||||
if (isCheckHash) {
|
||||
await this.checkTorrents({hashes}).catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
try {
|
||||
await this.checkTorrents({hashes});
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.startTorrents({hashes: hashesToRestart});
|
||||
|
||||
Reference in New Issue
Block a user