Refine link/embed resolution code

This commit is contained in:
Eric Bailey
2026-05-05 19:55:29 -05:00
parent a930e5832c
commit e245d760cf
3 changed files with 168 additions and 249 deletions
@@ -0,0 +1,26 @@
import {EmbeddingDisabledError} from '#/lib/api/resolve'
import {type LinkResolutionFailureCode} from '#/components/ComposerV2/store/types'
export type ParsedResolveLinkError = {
code: LinkResolutionFailureCode
/**
* Whether the failure is worth retrying. Today only EmbeddingDisabledError
* is permanent (the post's author has forbidden quoting); anything else
* is a transient or unknown failure and the caller should attach a
* `retry()` to the failed state.
*/
isRetryable: boolean
}
/**
* Classify a thrown error from `resolveLink` into a stable failure code
* and a retryability flag. Centralizes the retry-policy decision so the
* store doesn't repeat the `code === 'embedding-disabled'` check at every
* failure call site.
*/
export function parseResolveLinkError(err: unknown): ParsedResolveLinkError {
if (err instanceof EmbeddingDisabledError) {
return {code: 'embedding-disabled', isRetryable: false}
}
return {code: 'unknown', isRetryable: true}
}