handle errors

This commit is contained in:
Tobi Saputra 2023-03-25 00:51:45 +07:00
parent fc860d5cc0
commit e683e6fc62
2 changed files with 11 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@tobyg74/tiktok-api-dl",
"version": "1.0.0",
"version": "1.0.1-fix",
"description": "Scrapper for download Video, Image, Music from Tiktok",
"main": "index.js",
"scripts": {

View File

@ -11,17 +11,21 @@ const TiktokDL = (url) => {
})
.then(({ request }) => {
const { responseUrl } = request.res;
const ID = responseUrl.match(/\d{17,21}/g)[0];
let ID = responseUrl.match(/\d{17,21}/g)
if (ID === null) return reject({
status: "error",
message: "Failed to fetch tiktok url. Make sure your tiktok url is correct!",
});
ID = ID[0]
Axios(_tiktokapi(ID), {
method: "GET",
})
.then(({ data }) => {
const content = data.aweme_list.filter((v) => v.aweme_id === ID)[0];
if (content.aweme_id !== ID)
return resolve({
status: "error",
message: "Failed to find tiktok data. Make sure your tiktok url is correct!",
});
if (!content) return resolve({
status: "error",
message: "Failed to find tiktok data. Make sure your tiktok url is correct!",
});
const statistics = {
play_count: content.statistics.play_count,
download_count: content.statistics.download_count,