Skip to content

Commit b74304e

Browse files
committed
init logs
1 parent e87092b commit b74304e

File tree

6 files changed

+622
-17
lines changed

6 files changed

+622
-17
lines changed

.eslintrc.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

dist/data/1.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ module.exports =
22
/******/ (() => { // webpackBootstrap
33
/******/ var __webpack_modules__ = ({
44

5+
/***/ 524:
6+
/***/ ((module) => {
7+
8+
class FigshareAPIError extends Error {
9+
constructor(message) {
10+
super(message);
11+
this.name = 'FigshareAPIError';
12+
}
13+
}
14+
15+
module.exports = FigshareAPIError;
16+
17+
18+
/***/ }),
19+
520
/***/ 49:
621
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
722

@@ -10,6 +25,15 @@ module.exports =
1025

1126
const fetch = __nccwpck_require__(467);
1227

28+
const FigshareAPIError = __nccwpck_require__(524);
29+
30+
async function parseErrorResponse(resp) {
31+
const errStatus = resp.statusText;
32+
const errText = await resp.text();
33+
34+
return `${errStatus}: ${errText}`;
35+
}
36+
1337
class FigshareAPI {
1438
constructor(token, endpoint) {
1539
this.token = token;
@@ -25,6 +49,13 @@ class FigshareAPI {
2549
async getArticle(articleID) {
2650
const articleUrl = `${this.endpoint}/${this.articlePathPrefix}/${articleID}`;
2751
let articleData = await fetch(articleUrl, { headers: this.headers });
52+
53+
// possible configuration issue / invalid token
54+
if (!articleData.ok) {
55+
const message = await parseErrorResponse(articleData);
56+
throw new FigshareAPIError(message);
57+
}
58+
2859
articleData = await articleData.json();
2960

3061
return articleData;
@@ -41,6 +72,13 @@ class FigshareAPI {
4172
}),
4273
headers: this.headers,
4374
});
75+
76+
// possible quota limitation
77+
if (!fData.ok) {
78+
const message = await parseErrorResponse(fData);
79+
throw new FigshareAPIError(message);
80+
}
81+
4482
const jsonData = await fData.json();
4583

4684
const fileUrl = jsonData.location;

error.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class FigshareAPIError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this.name = 'FigshareAPIError';
5+
}
6+
}
7+
8+
module.exports = FigshareAPIError;

figshare.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33

44
const fetch = require('node-fetch');
55

6+
const FigshareAPIError = require('./error');
7+
8+
async function parseErrorResponse(resp) {
9+
const errStatus = resp.statusText;
10+
const errText = await resp.text();
11+
12+
return `${errStatus}: ${errText}`;
13+
}
14+
615
class FigshareAPI {
716
constructor(token, endpoint) {
817
this.token = token;
@@ -18,6 +27,13 @@ class FigshareAPI {
1827
async getArticle(articleID) {
1928
const articleUrl = `${this.endpoint}/${this.articlePathPrefix}/${articleID}`;
2029
let articleData = await fetch(articleUrl, { headers: this.headers });
30+
31+
// possible configuration issue / invalid token
32+
if (!articleData.ok) {
33+
const message = await parseErrorResponse(articleData);
34+
throw new FigshareAPIError(message);
35+
}
36+
2137
articleData = await articleData.json();
2238

2339
return articleData;
@@ -34,6 +50,13 @@ class FigshareAPI {
3450
}),
3551
headers: this.headers,
3652
});
53+
54+
// possible quota limitation
55+
if (!fData.ok) {
56+
const message = await parseErrorResponse(fData);
57+
throw new FigshareAPIError(message);
58+
}
59+
3760
const jsonData = await fData.json();
3861

3962
const fileUrl = jsonData.location;

0 commit comments

Comments
 (0)