Skip to content

Commit

Permalink
Added error handling for Lesson.startTime
Browse files Browse the repository at this point in the history
  • Loading branch information
loumadev committed Dec 9, 2021
1 parent 45f0563 commit 3fb31f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
17 changes: 14 additions & 3 deletions src/Lesson.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const {FatalError} = require("./exceptions");
const RawData = require("../lib/RawData");
const Assignment = require("./Assignment");
const Class = require("./Class");
Expand Down Expand Up @@ -112,6 +113,7 @@ class Lesson extends RawData {
*
* @param {Edupage} [edupage=null]
* @memberof Lesson
* @returns {void}
*/
init(edupage = null) {
if(edupage) this.edupage = edupage;
Expand All @@ -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]);
}
}

/**
Expand Down

0 comments on commit 3fb31f5

Please sign in to comment.