hijri-ma
Version:
```sh npm install ```
39 lines (31 loc) • 730 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fetchData = exports.ApiError = void 0;
const {
JSDOM
} = require('jsdom');
class ApiError extends Error {
constructor(message = 'API Error', status = 500) {
super(message);
this.status = status;
}
}
/**
*
*
* @param {*} url
* @param {*} [extractorFn=_ => _]
* @returns
*/
exports.ApiError = ApiError;
const fetchData = (url, extractorFn = _ => _) => {
return JSDOM.fromURL(url).then(document => document.window.document).then(document => {
return extractorFn(document);
}) //TODO: replace this by a better error handling 👇
.catch(_ => {
throw new ApiError();
});
};
exports.fetchData = fetchData;