File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " linkedapi-node" ,
3- "version" : " 1.2.5 " ,
3+ "version" : " 1.2.6 " ,
44 "description" : " Official TypeScript SDK for Linked API" ,
55 "main" : " dist/index.js" ,
66 "types" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -11,11 +11,26 @@ export async function pollWorkflowResult<TResult>(
1111 const { pollInterval = 5000 , timeout = 24 * 60 * 60 * 1000 } = options ;
1212 const startTime = Date . now ( ) ;
1313
14+ let invalidAttempts = 0 ;
15+ const maxInvalidAttempts = 15 ;
16+
1417 while ( Date . now ( ) - startTime < timeout ) {
15- const result = await workflowResultFn ( ) ;
18+ try {
19+ const result = await workflowResultFn ( ) ;
1620
17- if ( result !== 'running' ) {
18- return result ;
21+ if ( result !== 'running' ) {
22+ return result ;
23+ }
24+ invalidAttempts = 0 ;
25+ } catch ( error ) {
26+ if ( error instanceof LinkedApiError && error . type === 'httpError' ) {
27+ invalidAttempts = invalidAttempts + 1 ;
28+ if ( invalidAttempts > maxInvalidAttempts ) {
29+ throw error ;
30+ }
31+ } else {
32+ throw error ;
33+ }
1934 }
2035
2136 await sleep ( pollInterval ) ;
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ export const LINKED_API_ERROR = {
6262 linkedinAccountSignedOut : 'linkedinAccountSignedOut' ,
6363 languageNotSupported : 'languageNotSupported' ,
6464 workflowTimeout : 'workflowTimeout' ,
65+ httpError : 'httpError' ,
6566} as const ;
6667export type TLinkedApiErrorType = ( typeof LINKED_API_ERROR ) [ keyof typeof LINKED_API_ERROR ] ;
6768export class LinkedApiError extends Error {
You can’t perform that action at this time.
0 commit comments