Backend: Implement async error handling wrapper and refactor entry and media controllers to use it
This commit is contained in:
1 parent
ad58164df4
commit
4a1d2bc614
8 files changed
+92
-33
No files matched your search
@@ -23,6 +23,7 @@ const collectionManager = require('./collectionManager.js');
|
||||
const entryService = require("./entryService");
|
||||
const mediaManager = require("./mediaManager.js");
|
||||
const networkService = require("./networkService.js");
|
||||
const InternalServerError = require("../errors/InternalServerError.js");
|
||||
|
||||
const _collectionManager = collectionManager;
|
||||
const _entryService = entryService;
|
||||
@@ -56,6 +57,7 @@ class EntryManager {
|
||||
// * 2 - insert the entry into db
|
||||
const entry = await _entryService.createEntry(entryData, plain);
|
||||
|
||||
console.log('Entry created with ID:', entry.id, 'and title:', entry.title, 'and is_tvseries:', entry.is_tvseries);
|
||||
// * 3 - created the related collection
|
||||
if (entryData.belongs_to_collection && fetchCollection) {
|
||||
await _collectionManager.fetchAndSaveCollection(entryData.belongs_to_collection.id);
|
||||
@@ -461,7 +463,7 @@ class EntryManager {
|
||||
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||
|
||||
if (!entryData)
|
||||
throw ValidationError(`Couldn't Fetch Entry Data`);
|
||||
throw new ValidationError(`Couldn't Fetch Entry Data`);
|
||||
|
||||
// ! 1 - Normal Data
|
||||
let newData = {
|
||||
|
||||
@@ -121,6 +121,7 @@ class EntryService {
|
||||
async createEntry(data, plain = true) {
|
||||
// creating the object
|
||||
var is_tvseries = data.release_date == null ? true : false;
|
||||
console.log('entryService > createEntry > is_tvseries: ', is_tvseries);
|
||||
|
||||
let movie = Entry.build({
|
||||
title: data.title || data.name,
|
||||
@@ -147,6 +148,8 @@ class EntryService {
|
||||
|
||||
let savedEntry = await movie.save();
|
||||
|
||||
console.log('entryService > createEntry > savedEntry: ', savedEntry);
|
||||
|
||||
// ? ids
|
||||
await EntryId.create({
|
||||
entry_id: savedEntry.id,
|
||||
|
||||
@@ -660,7 +660,7 @@ async function SyncSerieData(entryId) {
|
||||
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||
|
||||
if (!entryData)
|
||||
throw ValidationError(`Couldn't Fetch Entry Data`);
|
||||
throw new ValidationError(`Couldn't Fetch Entry Data`);
|
||||
|
||||
// ! 1 - Normal Data
|
||||
let newData = {
|
||||
|
||||
Reference in new issue
Block a user