-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (26 loc) · 880 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const axios = require('axios');
const apiUrl = 'https://is-anything.com/api/record';
var is = function is(x) {
return new Proxy({}, {
get(target, property) {
return async function () {
try {
const response = await axios.get(apiUrl, {
params: {
subject: x,
predicate: property
}
});
return response.data.value;
} catch (error) {
if(error.response && error.response.status === 400) {
throw new Error(Object.values(error.response.data).flat().join(' '));
} else {
throw error;
}
}
};
}
});
}
module.exports = is;