UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

1 lines 2.35 kB
{"version":3,"file":"RetryAfterError.cjs","names":[],"sources":["../../src/components/RetryAfterError.ts"],"sourcesContent":["import ms from \"ms\";\n\n/**\n * An error that, when thrown, indicates to Inngest that the function should be\n * retried after a given amount of time.\n *\n * A `message` must be provided, as well as a `retryAfter` parameter, which can\n * be a `number` of milliseconds, an `ms`-compatible time string, or a `Date`.\n *\n * An optional `cause` can be provided to provide more context to the error.\n *\n * @public\n */\nexport class RetryAfterError extends Error {\n /**\n * The underlying cause of the error, if any.\n *\n * This will be serialized and sent to Inngest.\n */\n public override readonly cause?: unknown;\n\n /**\n * The time after which the function should be retried. Represents either a\n * number of milliseconds or a RFC3339 date.\n */\n public readonly retryAfter: string;\n\n constructor(\n message: string,\n\n /**\n * The time after which the function should be retried. Represents either a\n * number of milliseconds or a RFC3339 date.\n */\n retryAfter: number | string | Date,\n\n options?: {\n /**\n * The underlying cause of the error, if any.\n *\n * This will be serialized and sent to Inngest.\n */\n cause?: unknown;\n },\n ) {\n super(message);\n\n this.name = \"RetryAfterError\";\n\n if (retryAfter instanceof Date) {\n this.retryAfter = retryAfter.toISOString();\n } else {\n const seconds = `${Math.ceil(\n (typeof retryAfter === \"string\"\n ? ms(retryAfter as `${number}`)\n : retryAfter) / 1000,\n )}`;\n\n if (!isFinite(Number(seconds))) {\n throw new Error(\n \"retryAfter must be a number of milliseconds, a ms-compatible string, or a Date\",\n );\n }\n\n this.retryAfter = seconds;\n }\n\n this.cause = options?.cause;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,IAAa,kBAAb,cAAqC,MAAM;;;;;;CAMzC,AAAyB;;;;;CAMzB,AAAgB;CAEhB,YACE,SAMA,YAEA,SAQA;AACA,QAAM,QAAQ;AAEd,OAAK,OAAO;AAEZ,MAAI,sBAAsB,KACxB,MAAK,aAAa,WAAW,aAAa;OACrC;GACL,MAAM,UAAU,GAAG,KAAK,MACrB,OAAO,eAAe,2BAChB,WAA0B,GAC7B,cAAc,IACnB;AAED,OAAI,CAAC,SAAS,OAAO,QAAQ,CAAC,CAC5B,OAAM,IAAI,MACR,iFACD;AAGH,QAAK,aAAa;;AAGpB,OAAK,QAAQ,SAAS"}