Open nrathi opened 3 months ago
Hey @dantio, do you have time to take this on? I could take a stab at it, I think it's just one line.
We haven’t experienced this error yet, and I’m not sure how to reproduce it. If you can explain to me how to trigger this error message, I will try to fix it. Please go ahead if you have time to fix it. I would appreciate it. 😊
Here's a repro:
while (true) {
try {
const res = await this.api.trading.GetMyeBaySelling?.(
{
SoldList: {
DurationInDays: 60,
Include: true,
OrderStatusFilter: "All",
Sort: "EndTimeDescending",
},
},
{ useIaf: true },
);
console.log(res);
await new Promise((res) => setTimeout(res, 15 * 60 * 1000)); // 15 minutes
} catch (e) {
console.log(e);
}
}
And eventually, you'll get this error. The token should be refreshed and it isn't:
error: EbayApiError: Auth token is hard expired.
at checkEBayResponse (/Users/me/my-app/node_modules/.pnpm/ebay-api@8.7.1/node_modules/ebay-api/lib/errors/index.js:187:15)
at XMLRequest.request (/Users/me/my-app/node_modules/.pnpm/ebay-api@8.7.1/node_modules/ebay-api/lib/api/traditional/XMLRequest.js:118:46)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Traditional.request (/Users/me/my-app/node_modules/.pnpm/ebay-api@8.7.1/node_modules/ebay-api/lib/api/traditional/index.js:178:20)
at async Object.GetMyeBaySelling (/Users/me/my-app/node_modules/.pnpm/ebay-api@8.7.1/node_modules/ebay-api/lib/api/traditional/index.js:44:24) {
description: 'Auth token is hard expired, User needs to generate a new token for this application.',
meta: {
Timestamp: '2024-03-29T15:13:35.709Z',
Ack: 'Failure',
Errors: [Object],
Version: 1271,
Build: 'E1271_CORE_APISELLINGEXTSVC_R1',
[Symbol(raw-error)]: [Object]
}
},
Changing the "catch" as follows works:
} catch (e) {
if ( isEBayAuthTokenExpiredError(e)) {
await eBayApi.OAuth2.refreshToken();
return myRecursiveFunction(...);
}
throw e;
}
};
function isEBayAuthTokenExpiredError(err: unknown) {
return (
err instanceof EBayError &&
err.description.includes("Auth token is hard expired")
);
}
Ah, you are using the Auth token. I see. I'll add this check in the next release. Thank you!
I have published it as 8.7.2-RC.0
.
Thanks! I started using it. Will let you know if there are any issues.
Describe the bug I believe I have a use case where the token should automatically get refreshed, but it is not.
Code
Output
expected data
This error self-resolves, so I think it has to do with the token not being refreshed, and then some other call down the line does the refresh. https://community.ebay.com/t5/eBay-APIs-Talk-to-your-fellow/get-a-new-auth-token-where-do-i-go-to-get-it/td-p/33655751
Would you like to work on this issue?