mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-01-05 21:19:37 -06:00
Add error handling for plexApi
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
"custom-env": "^1.0.0",
|
||||
"dotenv": "^6.2.0",
|
||||
"express": "^4.16.4",
|
||||
"express-validator": "^5.3.1",
|
||||
"lodash": "^4.17.11",
|
||||
"morgan": "^1.9.1",
|
||||
"onchange": "^5.2.0",
|
||||
|
||||
@@ -17,9 +17,13 @@ const getUsers = async (req, res) => {
|
||||
};
|
||||
|
||||
const getMostWatched = async (req, res) => {
|
||||
const options = req.query;
|
||||
const mostWatched = await plexApi.getMostWatched(options);
|
||||
res.json(mostWatched);
|
||||
try {
|
||||
const options = req.query;
|
||||
const mostWatched = await plexApi.getMostWatched(options);
|
||||
res.json(mostWatched);
|
||||
} catch (error) {
|
||||
res.json(error);
|
||||
}
|
||||
};
|
||||
|
||||
const getSections = async (req, res) => {
|
||||
|
||||
@@ -46,17 +46,34 @@ const getLibraryDataBySectionUrlParams = function(options) {
|
||||
};
|
||||
|
||||
const getUsers = async function() {
|
||||
const urlParams = getUsersUrlParams();
|
||||
const getUsersUrl = helpers.buildUrl(urlParams);
|
||||
const response = await helpers.request(getUsersUrl);
|
||||
return response.MediaContainer.User;
|
||||
try {
|
||||
const urlParams = getUsersUrlParams();
|
||||
const getUsersUrl = helpers.buildUrl(urlParams);
|
||||
const response = await helpers.request(getUsersUrl);
|
||||
return response.MediaContainer.User;
|
||||
} catch (error) {
|
||||
return {
|
||||
code: error.status,
|
||||
message: error.statusText,
|
||||
url: error.config.url,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const getMostWatched = async function(options) {
|
||||
const urlParams = mostWatchedUrlParams(options);
|
||||
const mostWatchedUrl = helpers.buildUrl(urlParams);
|
||||
const response = await helpers.request(mostWatchedUrl);
|
||||
return response.MediaContainer.Metadata;
|
||||
try {
|
||||
const urlParams = mostWatchedUrlParams(options);
|
||||
const mostWatchedUrl = helpers.buildUrl(urlParams);
|
||||
const response = await helpers.request(mostWatchedUrl);
|
||||
return response.MediaContainer.Metadata;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
code: error.status,
|
||||
message: error.statusText,
|
||||
url: error.config.url,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const getSections = async function() {
|
||||
@@ -66,7 +83,11 @@ const getSections = async function() {
|
||||
const response = await helpers.request(getSectionsUrl);
|
||||
return response.MediaContainer.Directory;
|
||||
} catch (error) {
|
||||
return error;
|
||||
return {
|
||||
code: error.status,
|
||||
message: error.statusText,
|
||||
url: error.config.url,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,7 +98,11 @@ const getLibraryDataBySection = async function(options) {
|
||||
const response = await helpers.request(getLibraryDataBySectionUrl);
|
||||
return response.MediaContainer.Metadata;
|
||||
} catch (error) {
|
||||
return error;
|
||||
return {
|
||||
code: error.status,
|
||||
message: error.statusText,
|
||||
url: error.config.url,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user