Closed TheeMattOliver closed 2 years ago
Hey @TheeMattOliver, sorry for the late reply.
I tried this code:
async function test() {
const bitbucket = Bitbucket({
auth: {
username: 'MunifTanjim',
password: '<app-password>',
},
})
const currentUser = await bitbucket.users.getAuthedUser({})
console.log(JSON.stringify(currentUser, null, 2))
}
test()
And it worked as expected.
Looking at the error [HTTPError]: network timeout at: https://api.bitbucket.org/2.0/user
, it seems like your machine's network can't reach api.bitbucket.org
for some reason... maybe you're behind a firewall?
I don't think this is an issue with the library.
Thanks! Yeah, it's interesting, I'm not behind a firewall. I'm actually wondering if this has to do with something specific to the way I'm formatting the request in NextJS, but either way, yes, not an issue with the library so I closed it. Appreciate your taking a look!
I see that you're setting 20ms as timeout: https://github.com/TheeMattOliver/read-bitbucket-repo/blob/7f1635065325eb0737f04628a4bac9dff54eab81/pages/api/read-bitbucket-repo.js#L7
That's a very small time for a request. Try removing that timeout maybe?
That worked.
With the NextJS API routes, it looks like this:
export default async function handler(req, res) {
const currentUser = await bitbucket.users.getAuthedUser({});
res.status(200).json({ currentUser: currentUser });
try {
// do stuff
} catch (e) {
return e;
}
}
Hi Munif! 👋
Thanks for making this great library!
Had a quick question for you about
async...await
patterns and using the API.I need to write a method to recursively create a tree from the contents of a Bitbucket repo, similar to the Github API
createTree
method or Gitlab/gitbeaker'srepositories.tree
method. (If you felt like tackling that that would be amazing but I don't think it exists as a raw Bitbucket API endpoint 😅 ).To quickly start a basic proof of concept I just whipped up a quick NextJS app and am using api routes, but before I got too far I just wanted to solicit some feedback from you about using
async...await
and this error in particular:So to start out we have a basic function that just checks the currently authed user using
getAuthedUser
, and we wrap in try catch:That results in the following error:
If we don't wrap the call to the API in the
try
/catch
like this:We get:
API resolved without sending a response for /api/read-bitbucket-repo, this may result in stalled requests
, which indicates that we should be returning a Promise and resolving/rejecting it.What would you suggest here? I believe there's something I am missing between Promises, try...catch, and async await patterns, and just wanted to get your take on it.
You can try this out locally with this minimal repro.