mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2025-12-30 18:19:46 -06:00
Add error handler helper.
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -4,4 +4,11 @@ node_modules
|
||||
.nyc_output
|
||||
dist
|
||||
npm-debug.log
|
||||
coverage
|
||||
coverage
|
||||
.nycrc
|
||||
.npmignore
|
||||
.eslinstrc.js
|
||||
.DS_Store
|
||||
.prettierignore
|
||||
.prettierrc.json
|
||||
.sequelizerc
|
||||
@@ -50,4 +50,14 @@ const request = async function(url) {
|
||||
});
|
||||
};
|
||||
|
||||
export default {formatResponse, buildUrl, request};
|
||||
const handleError = (res, method) => err => {
|
||||
console.log('Error in', method);
|
||||
console.log(err);
|
||||
const {code, message} = err.responseData || {
|
||||
code: 500,
|
||||
message: 'An unknown error occurred.',
|
||||
};
|
||||
res.status(code).json({message});
|
||||
};
|
||||
|
||||
export default {formatResponse, buildUrl, request, handleError};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import plexApi from './plexApi';
|
||||
import importData from './importData';
|
||||
import auth from './auth';
|
||||
import helpers from './helpers';
|
||||
|
||||
const getAuthToken = async (req, res) => {
|
||||
const {username} = req.query;
|
||||
@@ -16,7 +17,7 @@ const getUsers = async (req, res) => {
|
||||
const users = await plexApi.getUsers();
|
||||
res.json(users);
|
||||
} catch (error) {
|
||||
res.json(error);
|
||||
helpers.handleError(res, getUsers.name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -101,8 +101,8 @@ describe('Library Data', () => {
|
||||
.request(app)
|
||||
.get('/api/users?X-Plex-Token')
|
||||
.end((err, res) => {
|
||||
console.log('error-mike--', res);
|
||||
res.should.have.status(404);
|
||||
console.log(res.body);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user