Skip to content

Commit 10ef223

Browse files
authored
Merge pull request #45 from Tch1b0/add-incompatible-plan-exception
Exceptions: add new IncompatiblePlan exception
2 parents 1c511fe + 92ad716 commit 10ef223

File tree

10 files changed

+35
-13
lines changed

10 files changed

+35
-13
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [10.x, 12.x, 14.x, 15.x, 16.x, 17.x]
10+
node-version: [10.x, 12.x, 14.x, 15.x, 16.x, 17.x, 18.x]
1111

1212
steps:
1313
- uses: actions/checkout@v2
1414

1515
- name: Setup Node.js ${{ matrix.node-version }}
16-
uses: actions/setup-node@v2.4.1
16+
uses: actions/setup-node@v3
1717
with:
1818
node-version: ${{ matrix.node-version }}
1919

@@ -30,9 +30,9 @@ jobs:
3030
- uses: actions/checkout@v2
3131

3232
- name: Setup Node.js 17.x
33-
uses: actions/setup-node@v2.4.1
33+
uses: actions/setup-node@v3
3434
with:
35-
node-version: 17.x
35+
node-version: 18.x
3636

3737
- name: Install dependencies
3838
run: npm ci

.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- uses: actions/setup-node@v2.4.1
13+
- uses: actions/setup-node@v3
1414
with:
1515
# Declare the registry where the package will be published
1616
registry-url: https://registry.npmjs.org/

.github/workflows/docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515

1616
- name: Setup node.js
17-
uses: actions/setup-node@v2.4.1
17+
uses: actions/setup-node@v3
1818

1919
- name: Install dependencies
2020
run: npm ci
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Deploy to GitHub Pages
2626
if: success()
27-
uses: crazy-max/ghaction-github-pages@v2
27+
uses: crazy-max/ghaction-github-pages@v3
2828
with:
2929
target_branch: gh-pages
3030
build_dir: docs

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# dsbmobile.js
22

33
![badge](https://img.shields.io/github/license/Tch1b0/dsbmobile.js)
4+
[![badge](https://img.shields.io/badge/docs-%F0%9F%93%96-blue)](https://tch1b0.github.io/dsbmobile.js/)
45
![badge](https://img.shields.io/github/workflow/status/Tch1b0/dsbmobile.js/ci?label=ci)
56
![badge](https://img.shields.io/github/issues/Tch1b0/dsbmobile.js)
67

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dsbmobile",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "A Javascript wrapper for the dsbmobile api",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/dsbmobile.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
2+
NewsPost,
23
DocumentPost,
34
DocumentPostCollection,
45
NewsPostCollection,
56
TimeTable,
67
MissingToken,
8+
IncompatiblePlan,
79
} from "./";
810
import axios from "axios";
9-
import { NewsPost } from "./";
1011
import { Requester } from "./requester";
1112

1213
/**
@@ -115,6 +116,7 @@ export default class Dsbmobile {
115116
/**
116117
* Get your current **Timetable**
117118
* @throws `MissingToken` if the token isn't declared
119+
* @throws `IncompatiblePlan` if the format of the targeted plan is not supported
118120
* @returns A new `TimeTable` resource
119121
*/
120122
public async getTimetable(): Promise<TimeTable> {
@@ -131,7 +133,11 @@ export default class Dsbmobile {
131133

132134
resp = await this.requester.get(resURL);
133135

134-
return TimeTable.fromHtml(resp.data);
136+
try {
137+
return TimeTable.fromHtml(resp.data);
138+
} catch (error) {
139+
throw new IncompatiblePlan();
140+
}
135141
}
136142

137143
/**

src/errors.ts

+8
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ export class UnknownFetchError extends Error {
4242
);
4343
}
4444
}
45+
46+
export class IncompatiblePlan extends Error {
47+
constructor() {
48+
super(
49+
"it seems like the format of the targeted substitution-plan is not supported. Please read https://github.com/Tch1b0/dsbmobile.js#incompatible-plan",
50+
);
51+
}
52+
}

src/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import Dsbmobile from "./dsbmobile";
22

33
export default Dsbmobile;
44
export { DsbmobileConfig } from "./dsbmobile";
5-
export { UnknownSubject, WrongCredentials, MissingToken } from "./errors";
5+
export {
6+
UnknownSubject,
7+
WrongCredentials,
8+
MissingToken,
9+
IncompatiblePlan,
10+
} from "./errors";
611
export { NewsPostCollection, NewsPost } from "./news";
712
export { TimeTable, Entry } from "./timetable";
813
export { DocumentPostCollection, DocumentPost } from "./documents";

tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "commonjs",
3+
"module": "CommonJS",
44
"baseUrl": "src",
55
"target": "es5",
66
"noImplicitAny": false,
@@ -13,5 +13,6 @@
1313
"downlevelIteration": true,
1414
"resolveJsonModule": true
1515
},
16-
"include": ["src/**/*"]
16+
"include": ["src/**/*"],
17+
"exclude": ["node_modules/**/*"]
1718
}

typedoc.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://typedoc.org/schema.json",
23
"entryPoints": ["./src/index.ts"],
34
"darkHighlightTheme": "dracula",
45
"out": "docs"

0 commit comments

Comments
 (0)