chore: added specific error message in wakatime card (#498)
This commit is contained in:
1 parent
a5d99aa5a9
commit
3443b37904
2 files changed
+14
-5
No files matched your search
@@ -1,11 +1,20 @@
|
|||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
|
||||||
const fetchLast7Days = async ({ username }) => {
|
const fetchLast7Days = async ({ username }) => {
|
||||||
const { data } = await axios.get(
|
try {
|
||||||
`https://wakatime.com/api/v1/users/${username}/stats/last_7_days?is_including_today=true`,
|
const { data } = await axios.get(
|
||||||
);
|
`https://wakatime.com/api/v1/users/${username}/stats/last_7_days?is_including_today=true`,
|
||||||
|
);
|
||||||
|
|
||||||
return data.data;
|
return data.data;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.response.status === 404) {
|
||||||
|
throw new Error(
|
||||||
|
"Wakatime user not found, make sure you have a wakatime profile",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ describe("Wakatime fetcher", () => {
|
|||||||
mock.onGet(/\/https:\/\/wakatime\.com\/api/).reply(404, wakaTimeData);
|
mock.onGet(/\/https:\/\/wakatime\.com\/api/).reply(404, wakaTimeData);
|
||||||
|
|
||||||
await expect(fetchLast7Days("noone")).rejects.toThrow(
|
await expect(fetchLast7Days("noone")).rejects.toThrow(
|
||||||
"Request failed with status code 404",
|
"Wakatime user not found, make sure you have a wakatime profile",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user