@pdfvector/client 0.0.30 → 0.0.32
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/CHANGELOG.md +16 -0
- package/README.md +85 -75
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @pdfvector/client
|
|
2
2
|
|
|
3
|
+
## 0.0.32
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies []:
|
|
7
|
+
- @pdfvector/instance-client@0.0.52
|
|
8
|
+
|
|
9
|
+
## 0.0.31
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
- [#244](https://github.com/phuctm97/pdfvector/pull/244) [`d751cdd`](https://github.com/phuctm97/pdfvector/commit/d751cdde1c208c3298d1a0c2c34406e724e53264) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Improve PDF Vector SDK error handling.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`d751cdd`](https://github.com/phuctm97/pdfvector/commit/d751cdde1c208c3298d1a0c2c34406e724e53264)]:
|
|
17
|
+
- @pdfvector/instance-client@0.0.51
|
|
18
|
+
|
|
3
19
|
## 0.0.30
|
|
4
20
|
### Patch Changes
|
|
5
21
|
|
package/README.md
CHANGED
|
@@ -611,10 +611,14 @@ console.log(resultB.documentId); // "doc-b"
|
|
|
611
611
|
|
|
612
612
|
## Error Handling
|
|
613
613
|
|
|
614
|
-
All API errors are thrown as `PDFVectorError` instances. The SDK
|
|
614
|
+
All API errors are thrown as `PDFVectorError` instances. The SDK maps server errors into specific subclasses and adds user/agent-friendly fields such as `title`, `suggestion`, `userError`, retry flags, and `requestId`.
|
|
615
615
|
|
|
616
616
|
```typescript
|
|
617
|
-
import {
|
|
617
|
+
import {
|
|
618
|
+
PDFVectorError,
|
|
619
|
+
createClient,
|
|
620
|
+
isPDFVectorUserError,
|
|
621
|
+
} from "@pdfvector/client";
|
|
618
622
|
|
|
619
623
|
const client = createClient({ apiKey: "your-api-key" });
|
|
620
624
|
|
|
@@ -624,35 +628,59 @@ try {
|
|
|
624
628
|
});
|
|
625
629
|
console.log(result.markdown);
|
|
626
630
|
} catch (error) {
|
|
631
|
+
if (isPDFVectorUserError(error)) {
|
|
632
|
+
console.error(error.title);
|
|
633
|
+
console.error(error.suggestion);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
|
|
627
637
|
if (error instanceof PDFVectorError) {
|
|
628
|
-
console.error(
|
|
629
|
-
console.error(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
638
|
+
console.error(error.supportMessage);
|
|
639
|
+
console.error(error.toAgentError());
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Network errors (DNS, connection refused, timeout) bubble up as TypeError.
|
|
644
|
+
console.error("Unexpected Error:", error);
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### User errors
|
|
649
|
+
|
|
650
|
+
Use `isPDFVectorUserError(error)` or `error.userError` for caller-fixable failures that should usually be shown to the user instead of reported as system failures. For example, URL input failures such as `URL did not return a supported document` are `URLFetchError` instances with `userError: true`.
|
|
651
|
+
|
|
652
|
+
```typescript
|
|
653
|
+
import { isPDFVectorUserError, isPDFVectorError } from "@pdfvector/client";
|
|
654
|
+
|
|
655
|
+
try {
|
|
656
|
+
await client.document.parse({ url: "https://example.com/page.html" });
|
|
657
|
+
} catch (error) {
|
|
658
|
+
if (isPDFVectorUserError(error)) {
|
|
659
|
+
console.error(error.suggestion);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (isPDFVectorError(error) && error.retryableWithHigherModel) {
|
|
663
|
+
console.error("Retry with a stronger model or a smaller document.");
|
|
636
664
|
}
|
|
637
665
|
}
|
|
638
666
|
```
|
|
639
667
|
|
|
640
668
|
### Branching on specific error types
|
|
641
669
|
|
|
642
|
-
Every error class extends `PDFVectorError`, so you can use `instanceof` to handle specific cases. Specialized subclasses expose typed fields pulled from the error
|
|
670
|
+
Every error class extends `PDFVectorError`, so you can use `instanceof` to handle specific cases. Specialized subclasses expose typed fields pulled from the error payload:
|
|
643
671
|
|
|
644
672
|
```typescript
|
|
645
673
|
import {
|
|
646
|
-
|
|
674
|
+
EmptyDocumentError,
|
|
675
|
+
ExtractionFailedError,
|
|
647
676
|
FileTooLargeError,
|
|
677
|
+
InvalidSchemaError,
|
|
678
|
+
NoPublicPDFError,
|
|
648
679
|
PageLimitExceededError,
|
|
649
680
|
PasswordProtectedError,
|
|
650
|
-
URLFetchError,
|
|
651
|
-
UnauthorizedError,
|
|
652
681
|
TooManyRequestsError,
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
PDFVectorError,
|
|
682
|
+
UnauthorizedError,
|
|
683
|
+
URLFetchError,
|
|
656
684
|
} from "@pdfvector/client";
|
|
657
685
|
|
|
658
686
|
try {
|
|
@@ -664,14 +692,18 @@ try {
|
|
|
664
692
|
);
|
|
665
693
|
} else if (error instanceof PageLimitExceededError) {
|
|
666
694
|
console.error(
|
|
667
|
-
`Document has ${error.pageCount} pages
|
|
695
|
+
`Document has ${error.pageCount} pages; ${error.model} supports up to ${error.pageLimit}`,
|
|
668
696
|
);
|
|
669
697
|
} else if (error instanceof PasswordProtectedError) {
|
|
670
698
|
console.error("Remove the password from the file and try again");
|
|
671
699
|
} else if (error instanceof URLFetchError) {
|
|
672
|
-
console.error(
|
|
700
|
+
console.error(error.suggestion);
|
|
701
|
+
} else if (error instanceof InvalidSchemaError) {
|
|
702
|
+
console.error(error.reason);
|
|
703
|
+
} else if (error instanceof NoPublicPDFError) {
|
|
704
|
+
console.error("Provide a direct PDF URL or upload the paper file directly");
|
|
673
705
|
} else if (error instanceof UnauthorizedError) {
|
|
674
|
-
console.error("Invalid API key
|
|
706
|
+
console.error("Invalid API key; check your dashboard");
|
|
675
707
|
} else if (error instanceof TooManyRequestsError) {
|
|
676
708
|
console.error(`Rate limit ${error.limit} exceeded; resets at ${error.resetAt}`);
|
|
677
709
|
} else if (error instanceof EmptyDocumentError) {
|
|
@@ -679,34 +711,6 @@ try {
|
|
|
679
711
|
} else if (error instanceof ExtractionFailedError) {
|
|
680
712
|
console.error(`Extraction failed. Hint: ${error.hint}`);
|
|
681
713
|
if (error.rawText) console.error(`Model output sample: ${error.rawText}`);
|
|
682
|
-
} else if (error instanceof PDFVectorError) {
|
|
683
|
-
// Catch-all for any error code not specifically handled
|
|
684
|
-
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
```
|
|
688
|
-
|
|
689
|
-
You can also branch on the error code if you prefer:
|
|
690
|
-
|
|
691
|
-
```typescript
|
|
692
|
-
try {
|
|
693
|
-
await client.document.parse({ url: "..." });
|
|
694
|
-
} catch (error) {
|
|
695
|
-
if (error instanceof PDFVectorError) {
|
|
696
|
-
switch (error.code) {
|
|
697
|
-
case "UNAUTHORIZED":
|
|
698
|
-
console.error("Invalid API key");
|
|
699
|
-
break;
|
|
700
|
-
case "BAD_REQUEST":
|
|
701
|
-
console.error("Validation error:", error.message);
|
|
702
|
-
break;
|
|
703
|
-
case "UNPROCESSABLE_CONTENT":
|
|
704
|
-
console.error("Could not process document:", error.message);
|
|
705
|
-
break;
|
|
706
|
-
case "INTERNAL_SERVER_ERROR":
|
|
707
|
-
console.error(`Server error (requestId: ${error.requestId}):`, error.message);
|
|
708
|
-
break;
|
|
709
|
-
}
|
|
710
714
|
}
|
|
711
715
|
}
|
|
712
716
|
```
|
|
@@ -721,13 +725,17 @@ PDFVectorError
|
|
|
721
725
|
│ ├── PasswordProtectedError
|
|
722
726
|
│ ├── UnsupportedFormatError — format, supportedFormats
|
|
723
727
|
│ ├── URLFetchError — url, statusCode, statusText
|
|
728
|
+
│ ├── InvalidDocumentURLError
|
|
729
|
+
│ ├── InvalidBase64Error
|
|
724
730
|
│ ├── TierNotSupportedError — documentType, model, allowedTypes
|
|
725
731
|
│ ├── InvalidSchemaError — reason
|
|
726
732
|
│ └── NoInputProvidedError
|
|
727
733
|
├── UnauthorizedError (401)
|
|
728
734
|
├── NotFoundError (404)
|
|
735
|
+
│ ├── AcademicPaperNotFoundError — input, paperErrorCode
|
|
736
|
+
│ └── NoPublicPDFError — input, paperTitle, doi, providerURL
|
|
729
737
|
├── ConflictError (409)
|
|
730
|
-
├── TooManyRequestsError (429) — limit, resetAt
|
|
738
|
+
├── TooManyRequestsError (429) — limit, resetAt, retryAfterSeconds
|
|
731
739
|
├── UnprocessableContentError (422)
|
|
732
740
|
│ ├── EmptyDocumentError
|
|
733
741
|
│ ├── NoTextDetectedError
|
|
@@ -740,42 +748,36 @@ PDFVectorError
|
|
|
740
748
|
|
|
741
749
|
| Field | Type | Description |
|
|
742
750
|
|-------|------|-------------|
|
|
743
|
-
| `code` | `string` |
|
|
744
|
-
| `status` | `number` | HTTP status code
|
|
745
|
-
| `
|
|
746
|
-
| `
|
|
747
|
-
| `
|
|
751
|
+
| `code` | `string` | API error code (`BAD_REQUEST`, `UNAUTHORIZED`, etc.) |
|
|
752
|
+
| `status` | `number` | HTTP-style status code |
|
|
753
|
+
| `title` | `string` | Short readable summary |
|
|
754
|
+
| `message` | `string` | Server-provided error message |
|
|
755
|
+
| `suggestion` | `string` | Recommended next action |
|
|
756
|
+
| `category` | `string` | `authentication`, `validation`, `document_input`, `document_processing`, `rate_limit`, `not_found`, `conflict`, `unsupported`, or `server` |
|
|
757
|
+
| `origin` | `"user" \| "system"` | Whether the failure is caller-fixable or likely server/provider-side |
|
|
758
|
+
| `userError` | `boolean` | `true` for expected caller-fixable failures |
|
|
759
|
+
| `retryable` | `boolean` | `true` when retrying may help |
|
|
760
|
+
| `retryableWithHigherModel` | `boolean` | `true` when retrying with a stronger model or smaller document may help |
|
|
761
|
+
| `requestId` | `number \| undefined` | Server-assigned request ID; include in support tickets |
|
|
748
762
|
| `documentId` | `string \| undefined` | Echoed back if you passed `context.documentId` |
|
|
749
|
-
| `
|
|
750
|
-
| `
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
If you'd rather not import `PDFVectorError` just to do an `instanceof` check, use the `isPDFVectorError` guard:
|
|
755
|
-
|
|
756
|
-
```typescript
|
|
757
|
-
import { isPDFVectorError } from "@pdfvector/client";
|
|
763
|
+
| `reasonCode` | `string \| undefined` | More specific server reason when available, such as `NO_PUBLIC_PDF` |
|
|
764
|
+
| `supportMessage` | `string` | Compact support/logging message |
|
|
765
|
+
| `data` | `Record<string, unknown>` | Raw error payload from the server |
|
|
766
|
+
| `cause` | `unknown` | Original underlying error |
|
|
758
767
|
|
|
759
|
-
|
|
760
|
-
await client.document.parse({ url: "..." });
|
|
761
|
-
} catch (error) {
|
|
762
|
-
if (isPDFVectorError(error)) {
|
|
763
|
-
console.error(error.code, error.message, error.requestId);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
```
|
|
768
|
+
Use `error.toAgentError()` or `JSON.stringify(error)` when you need a serializable error object for logs, workflows, retry planners, or agent tool responses.
|
|
767
769
|
|
|
768
770
|
### Error Codes
|
|
769
771
|
|
|
770
772
|
| Code | Status | Description |
|
|
771
773
|
|------|--------|-------------|
|
|
772
|
-
| `BAD_REQUEST` | 400 | Input validation failed
|
|
774
|
+
| `BAD_REQUEST` | 400 | Input validation failed, including invalid URLs, unsupported formats, file size limits, page limits, invalid base64, and invalid JSON Schema |
|
|
773
775
|
| `UNAUTHORIZED` | 401 | Missing or invalid API key |
|
|
774
|
-
| `NOT_FOUND` | 404 | Resource not found
|
|
776
|
+
| `NOT_FOUND` | 404 | Resource not found, including academic paper IDs and papers without public PDFs |
|
|
775
777
|
| `CONFLICT` | 409 | Operation conflicts with the current state |
|
|
776
|
-
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed
|
|
778
|
+
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed, including empty documents, no readable text, and extraction failures |
|
|
777
779
|
| `TOO_MANY_REQUESTS` | 429 | Rate limit exceeded |
|
|
778
|
-
| `INTERNAL_SERVER_ERROR` | 500 | Server-side failure
|
|
780
|
+
| `INTERNAL_SERVER_ERROR` | 500 | Server-side failure; capture the `requestId` for support |
|
|
779
781
|
| `NOT_IMPLEMENTED` | 501 | Endpoint not available on this instance |
|
|
780
782
|
|
|
781
783
|
## TypeScript Support
|
|
@@ -786,6 +788,7 @@ The SDK is written in TypeScript and includes full type definitions:
|
|
|
786
788
|
import {
|
|
787
789
|
createClient,
|
|
788
790
|
isPDFVectorError,
|
|
791
|
+
isPDFVectorUserError,
|
|
789
792
|
// Base error class — all errors inherit from this
|
|
790
793
|
PDFVectorError,
|
|
791
794
|
// HTTP-aligned error categories
|
|
@@ -803,12 +806,16 @@ import {
|
|
|
803
806
|
PasswordProtectedError,
|
|
804
807
|
UnsupportedFormatError,
|
|
805
808
|
URLFetchError,
|
|
809
|
+
InvalidDocumentURLError,
|
|
810
|
+
InvalidBase64Error,
|
|
806
811
|
TierNotSupportedError,
|
|
807
812
|
InvalidSchemaError,
|
|
808
813
|
NoInputProvidedError,
|
|
809
814
|
EmptyDocumentError,
|
|
810
815
|
NoTextDetectedError,
|
|
811
816
|
ExtractionFailedError,
|
|
817
|
+
AcademicPaperNotFoundError,
|
|
818
|
+
NoPublicPDFError,
|
|
812
819
|
// Underlying ORPC error — re-exported for advanced use cases
|
|
813
820
|
ORPCError,
|
|
814
821
|
} from "@pdfvector/client";
|
|
@@ -820,7 +827,10 @@ import type {
|
|
|
820
827
|
ContractInputs,
|
|
821
828
|
ContractOutputs,
|
|
822
829
|
PDFVectorModel,
|
|
830
|
+
PDFVectorAgentError,
|
|
831
|
+
PDFVectorErrorCategory,
|
|
823
832
|
PDFVectorErrorCode,
|
|
833
|
+
PDFVectorErrorOrigin,
|
|
824
834
|
} from "@pdfvector/client";
|
|
825
835
|
```
|
|
826
836
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfvector/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official TypeScript/JavaScript SDK for PDF Vector API",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"main": ".tsc/lib/index.js",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pdfvector/instance-client": "^0.0.
|
|
26
|
+
"@pdfvector/instance-client": "^0.0.52"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
".tsc",
|