Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating the multiple links throws error. #7

Open
chintanshahts opened this issue Sep 8, 2022 · 9 comments
Open

Creating the multiple links throws error. #7

chintanshahts opened this issue Sep 8, 2022 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@chintanshahts
Copy link

image

@IchiiDev
Copy link
Owner

IchiiDev commented Sep 8, 2022

Hey there, can you send a quick code snippet to see what went wrong? And how many links did you push at once?

@chintanshahts
Copy link
Author

chintanshahts commented Sep 8, 2022

const shortio = require("short.io");
require("dotenv").config();

const short = new shortio(
  process.env.SHORT_IO_DOMAIN,
  process.env.SHORT_IO_DOMAIN_ID,
  process.env.SHORT_IO_DOMAIN_KEY
);
const link = "https://google.com?id=";

const getLink = async (survey_id) => {
  const formLink = await short.createLink({
    originalURL: `${link}${survey_id}`,
  });
  console.log("formLink->>", formLink);
};

const main = async () => {
  const ids = [...Array(51).keys()];

  const promises = [];
  ids.forEach((id) => {
    promises.push(getLink(id));
  });

  await Promise.all(promises)
    .then((values) => {
      console.log("Link promises :::::::: ", values);
    })
    .catch((error) => {
      console.log("Link promise error::::::::", error);
    });
};

main();

@chintanshahts
Copy link
Author

image
Maybe you're trying to do response.json() after the fetch request. We need to handle the error as well.

image

@IchiiDev
Copy link
Owner

IchiiDev commented Sep 8, 2022

I'm going to work on a fix, but I would rather recommend you use the createLinkBulk method in order to push multiple links, it takes the same object structure as the createLink method, but an array of them. Tell me if this changed anything ! 🙏
Also, sorry for sleeping on the docs, once I will have the time to work on version 2, I will write correct docs.

@chintanshahts
Copy link
Author

@IchiiDev
Is this error due to throttling?

@IchiiDev
Copy link
Owner

IchiiDev commented Sep 8, 2022

@IchiiDev
Is this error due to throttling?

Honestly, I have no idea what causes this error to show up. As I said, the createLinkBulk method exists to send groups of links at once, so it would be best for now to stick to it until we figure out what's happening.

@chintanshahts
Copy link
Author

More details :

Node : v16.15.0
NPM: 8.12.1

@IchiiDev
Copy link
Owner

IchiiDev commented Sep 8, 2022

Is it still doing it even with the createLinkBulk method ?

@chintanshahts
Copy link
Author

Nope, It's working with the createLinkBulk

@IchiiDev IchiiDev self-assigned this Sep 8, 2022
@IchiiDev IchiiDev added the bug Something isn't working label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

2 participants