@crosspost/sdk 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@ bun install @crosspost/sdk
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { ApiError, CrosspostClient, isAuthError, PlatformError } from '@crosspost/sdk';
14
+ import { CrosspostClient, CrosspostError, isAuthError } from '@crosspost/sdk';
15
15
 
16
16
  // Initialize the client (authentication can be provided later)
17
17
  const client = new CrosspostClient({
@@ -43,7 +43,7 @@ async function authorizeNearAccount() {
43
43
  return true;
44
44
  } catch (error) {
45
45
  console.error('NEAR authorization failed');
46
- if (error instanceof ApiError) {
46
+ if (error instanceof CrosspostError) {
47
47
  console.error('Error code:', error.code);
48
48
  console.error('Status:', error.status);
49
49
  console.error('Details:', error.details);
@@ -64,7 +64,7 @@ async function unauthorizeNearAccount() {
64
64
  return true;
65
65
  } catch (error) {
66
66
  console.error('Failed to unauthorize NEAR account');
67
- if (error instanceof ApiError) {
67
+ if (error instanceof CrosspostError) {
68
68
  console.error('Error code:', error.code);
69
69
  console.error('Status:', error.status);
70
70
  console.error('Details:', error.details);
@@ -85,7 +85,7 @@ async function revokePlatformAuth(platform) {
85
85
  return true;
86
86
  } catch (error) {
87
87
  console.error(`Failed to revoke ${platform} authorization`);
88
- if (error instanceof ApiError) {
88
+ if (error instanceof CrosspostError) {
89
89
  console.error('Error code:', error.code);
90
90
  console.error('Status:', error.status);
91
91
  console.error('Details:', error.details);
@@ -120,15 +120,25 @@ async function createPost() {
120
120
  } else {
121
121
  // Handle other error types
122
122
  console.error('Error creating post:', error);
123
- if (error instanceof ApiError) {
124
- console.error('Error code:', error.code);
125
- console.error('Status:', error.status);
126
- console.error('Details:', error.details);
127
- console.error('Recoverable:', error.recoverable);
128
- } else if (error instanceof PlatformError) {
129
- console.error('Platform:', error.platform);
130
- console.error('Error code:', error.code);
131
- console.error('Original error:', error.originalError);
123
+ if (error instanceof CrosspostError) {
124
+ // Use error utility functions to handle specific cases
125
+ if (isPlatformError(error)) {
126
+ console.error('Platform:', error.platform);
127
+ console.error('Error code:', error.code);
128
+ console.error('Details:', error.details);
129
+ } else if (isRateLimitError(error)) {
130
+ console.error('Rate limited until:', error.details?.rateLimit?.reset);
131
+ } else if (isValidationError(error)) {
132
+ console.error('Validation errors:', error.details?.validationErrors);
133
+ }
134
+
135
+ // Check if error is recoverable
136
+ if (error.recoverable) {
137
+ console.log('This error is recoverable - retry may succeed');
138
+ }
139
+ } else if (error instanceof Error) {
140
+ // Handle non-API errors (network issues, etc)
141
+ console.error('Unexpected error:', error.message);
132
142
  }
133
143
  }
134
144
  }