Skip to content

Every failed request throws a SocifyrError, which carries the HTTP status code and the human-readable error message from the API.

SocifyrError

typescript
import { SocifyrError } from '@socifyr/sdk'

try {
  await socifyr.uploads.text({
    connections: ['nonexistent-slug'],
    text: 'hi',
  })
} catch (err) {
  if (err instanceof SocifyrError) {
    console.log(err.status)  // 400
    console.log(err.message) // 'Connection "nonexistent-slug" not found'
    console.log(err.body)    // full API response object
  }
}

Common status codes

StatusMeaningWhat to do
400Bad request — invalid params, missing fields, validation errorsFix the request payload
401Bad / missing API keyCheck apiKey and workspaceId
403API key valid but lacks permission for this workspace / actionCheck the key's workspace and role
404Resource doesn't existVerify the ID
409Conflict — e.g. trying to publish an already-published postOften safe to ignore
422Platform rejected the content (caption too long, image too small)Read err.message for the specific reason
429Rate limitedSDK retries automatically; if you still hit this, slow down
5xxServer-side failureSDK retries; if persistent, contact support

Validation errors

The API returns validation errors as a string array. The SDK joins them into one message:

typescript
// Backend response:
//   { success: false, error: ["text must be a string", "connections should not be empty"] }
// SDK throws:
//   SocifyrError { message: "text must be a string, connections should not be empty" }

Network errors

Transient failures (DNS errors, timeouts, 5xx) are retried up to maxRetries times. After exhausting retries, the SDK throws a SocifyrError with status: 0 and a message like "Network error: ...".

Pattern: graceful fallback

typescript
async function postSafely(params: UploadTextParams): Promise<Upload | null> {
  try {
    return await socifyr.uploads.text(params)
  } catch (err) {
    if (err instanceof SocifyrError) {
      if (err.status === 429) {
        console.warn('Rate limited, will retry later')
        return null
      }
      if (err.status >= 400 && err.status < 500) {
        console.error('Client error — not retrying:', err.message)
        return null
      }
    }
    throw err // unknown error — let it bubble
  }
}

Patterns: matching on message

The error messages are stable enough to match on:

typescript
catch (err) {
  if (err instanceof SocifyrError && err.message.includes('Token has expired')) {
    // Surface to the user — they need to reconnect this platform
  }
}