From 3fb31f5d38d31c2f3c8e7b6d37edad980e0c2585 Mon Sep 17 00:00:00 2001 From: Jaroslav Louma Date: Fri, 10 Dec 2021 00:57:26 +0100 Subject: [PATCH] Added error handling for `Lesson.startTime` --- package.json | 2 +- src/Lesson.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4e81be3..eab57bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "edupage-api", - "version": "0.7.12", + "version": "0.7.13", "description": "Simple node.js package to manage your EduPage account.", "main": "index.js", "scripts": { diff --git a/src/Lesson.js b/src/Lesson.js index b89d8bb..9e6bb2c 100644 --- a/src/Lesson.js +++ b/src/Lesson.js @@ -1,3 +1,4 @@ +const {FatalError} = require("./exceptions"); const RawData = require("../lib/RawData"); const Assignment = require("./Assignment"); const Class = require("./Class"); @@ -112,6 +113,7 @@ class Lesson extends RawData { * * @param {Edupage} [edupage=null] * @memberof Lesson + * @returns {void} */ init(edupage = null) { if(edupage) this.edupage = edupage; @@ -126,9 +128,18 @@ class Lesson extends RawData { this.edupage.assignments.find(e => e.hwkid && e.hwkid.includes(id.split(":")[1] || id)) ); - //Set the lesson start time - const d = this.period.startTime.split(":"); - this.date.setHours(+d[0], +d[1]); + if(!this.period) { + return FatalError.warn(new ReferenceError("Failed to find period for lesson"), { + query: this._data.flags.dp0.period, + periods: this.edupage.periods, + _data_lesson: this._data, + _data_edupage: this.edupage._data.dbi?.periods + }); + } else { + //Set the lesson start time + const d = this.period.startTime.split(":"); + this.date.setHours(+d[0], +d[1]); + } } /**