Skip to content

Throw specific error keys if available for getTimetableForWeek #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,17 @@ class WebUntis {
});

if (typeof response.data.data !== 'object') throw new Error('Server returned invalid data.');
if (
!response.data.data.result ||
!response.data.data.result.data ||
!response.data.data.result.data.elementPeriods ||
!response.data.data.result.data.elementPeriods[id]
)

if (response.data.data.error) {
/* known codes:
* - ERR_TTVIEW_NOTALLOWED_ONDATE
*/
const err = new Error("Server responded with error");
err.code = response.data.data.error?.data?.messageKey;
throw err;
}

if (!response.data.data.result?.data?.elementPeriods?.[id])
throw new Error('Invalid response');

const data = response.data.data.result.data;
Expand Down