{"record":{"id":"3c8714e98e83518b","repo":"laurent22/joplin","slug":"rejectedbytarget-3c8714","errorCode":"rejectedByTarget","errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"JoplinError","httpStatus":null,"severity":"error","filePath":"packages/lib/file-api-driver-joplinServer.ts","lineNumber":204,"sourceCode":"\t}\n\n\tprivate isRejectedBySyncTargetError(error: { code?: number | string; httpCode?: number }) {\n\t\treturn error.code === 413 || error.code === 409 || error.httpCode === 413 || error.httpCode === 409;\n\t}\n\n\tprivate isReadyOnlyError(error: { code?: string }) {\n\t\treturn error && error.code === 'isReadOnly';\n\t}\n\n\tpublic async put(path: string, content: string | Buffer | null, options: ExecOptions & { shareId?: string } = null) {\n\t\ttry {\n\t\t\tconst output = await this.api().exec('PUT', `${this.apiFilePath_(path)}/content`, options && options.shareId ? { share_id: options.shareId } : null, content, {\n\t\t\t\t'Content-Type': 'application/octet-stream',\n\t\t\t}, options);\n\t\t\treturn output;\n\t\t} catch (error) {\n\t\t\tif (this.isRejectedBySyncTargetError(error)) {\n\t\t\t\tthrow new JoplinError(error.message, 'rejectedByTarget');\n\t\t\t}\n\n\t\t\tif (this.isReadyOnlyError(error)) {\n\t\t\t\tthrow new JoplinError(error.message, 'isReadOnly');\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic async multiPut(items: MultiPutItem[], options: ExecOptions = null) {\n\t\tconst output = await this.api().exec('PUT', 'api/batch_items', null, { items: items }, null, options);\n\n\t\tfor (const [, response] of Object.entries<{ error?: { code?: string | number; httpCode?: number } }>(output.items)) {\n\t\t\tif (response.error && this.isRejectedBySyncTargetError(response.error)) {\n\t\t\t\tresponse.error.code = 'rejectedByTarget';\n\t\t\t} else if (response.error && this.isReadyOnlyError(response.error as { code?: string })) {\n\t\t\t\tresponse.error.code = 'isReadOnly';","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/lib/file-api-driver-joplinServer.ts#L186-L222","documentation":"Re-thrown by the Joplin Server driver when a PUT to .../content fails with HTTP 413 (payload too large) or 409 (conflict). The driver detects these via isRejectedBySyncTargetError and wraps them in a JoplinError with code 'rejectedByTarget', signaling the sync target refused the item so the synchronizer can handle it specially rather than treat it as a generic network error.","triggerScenarios":"Uploading note/resource content to Joplin Server where the body exceeds the server's max payload (413), or a concurrent sync/lock conflict produced a 409. The PUT is the per-item content upload inside put().","commonSituations":"Attaching a very large resource (image, PDF) exceeding the server upload limit; two clients editing and syncing the same item simultaneously; server-side quota reached; older server version with stricter limits.","solutions":["Check the underlying HTTP code (413 vs 409) in the wrapped error.message — 413 means reduce payload size or raise the server's upload limit; 409 means resolve the sync conflict and re-sync.","For 413: increase Joplin Server max body size / resource size cap, or split/truncate the resource.","For 409: let the normal sync conflict resolution run, or force-sync the item after confirming no other client is mid-edit.","Ensure the Joplin Server and client versions are compatible."],"exampleFix":"// before\nawait fileApi.put(path, content, { shareId });\n// after - branch on the re-thrown code\ntry { await fileApi.put(path, content, { shareId }); }\ncatch (e) {\n  if (e.code === 'rejectedByTarget') {\n    if (/413|too large|payload/i.test(e.message)) throw new Error('Resource exceeds server limit');\n    // 409 conflict - defer to conflict resolution\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check size if known to avoid a 413 round-trip.\nif (content && typeof content === 'string' && content.length > MAX_PUT_BYTES) {\n  throw new Error('Payload too large for Joplin Server');\n}","typeGuard":"function isRejectedByTarget(e: any): e is { code: 'rejectedByTarget'; message: string } {\n  return e && e.code === 'rejectedByTarget';\n}","tryCatchPattern":"try {\n  await fileApi.put(path, content, { shareId });\n} catch (e) {\n  if (isRejectedByTarget(e)) {\n    if (/413|too large/i.test(e.message)) { /* shrink resource or raise server limit */ }\n    else { /* 409 conflict - defer to sync conflict resolution */ }\n  } else throw e;\n}","preventionTips":["Size-check large resources before upload to avoid 413.","Avoid concurrent edits on the same item from two clients to prevent 409.","Keep Joplin Server and client versions in sync.","Surface rejectedByTarget distinctly from network errors in your retry logic."],"tags":["joplin-server","sync","http-413","http-409","conflict"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}