Fix: Linter warnings (#137)

* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation

* fix: updated plex_userid to camelcase

* Linted and some consistency refactor on middleware

* eslint uses ecmaversion 2020 & allow empty catch rule

* Started linting source files

* Fixed eslint errors & improved a lot of error handling

* Set 2 eslint rules as warning temporarly
This commit is contained in:
2022-08-20 17:21:25 +02:00
committed by GitHub
parent cfbd4965db
commit 1815a429b0
83 changed files with 1625 additions and 1294 deletions

View File

@@ -1,19 +1,33 @@
const UserRepository = require("../../../user/userRepository");
const userRepository = new UserRepository();
const fetch = require("node-fetch");
const FormData = require("form-data");
const UserRepository = require("../../../user/userRepository");
const userRepository = new UserRepository();
class PlexAuthenticationError extends Error {
constructor(errorResponse, statusCode) {
const message =
"Unexptected error while authenticating to plex signin api. View error response.";
super(message);
this.errorResponse = errorResponse;
this.statusCode = statusCode;
this.success = false;
}
}
function handleError(error, res) {
let { status, message, source } = error;
const status = error?.status;
let { message, source } = error;
if (status && message) {
if (status === 401) {
(message = "Unauthorized. Please check plex credentials."),
(source = "plex");
message = "Unauthorized. Please check plex credentials.";
source = "plex";
}
res.status(status).send({ success: false, message, source });
} else {
// eslint-disable-next-line no-console
console.log("caught authenticate plex account controller error", error);
res.status(500).send({
message:
@@ -25,11 +39,7 @@ function handleError(error, res) {
function handleResponse(response) {
if (!response.ok) {
throw {
success: false,
status: response.status,
message: response.statusText
};
throw new PlexAuthenticationError(response.statusText, response.status);
}
return response.json();
@@ -63,7 +73,7 @@ function link(req, res) {
return plexAuthenticate(username, password)
.then(plexUser => userRepository.linkPlexUserId(user.username, plexUser.id))
.then(response =>
.then(() =>
res.send({
success: true,
message:
@@ -78,7 +88,7 @@ function unlink(req, res) {
return userRepository
.unlinkPlexUserId(username)
.then(response =>
.then(() =>
res.send({
success: true,
message: "Successfully unlinked plex account from seasoned request."