@pdfvector/client 0.0.22 → 0.0.25
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 +26 -0
- package/README.md +148 -13
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @pdfvector/client
|
|
2
2
|
|
|
3
|
+
## 0.0.25
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [[`5d72a6c`](https://github.com/phuctm97/pdfvector/commit/5d72a6cb2dc5535b8c624f25709f8ae7fd9cc15b)]:
|
|
7
|
+
- @pdfvector/instance-client@0.0.45
|
|
8
|
+
|
|
9
|
+
## 0.0.24
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
- [#222](https://github.com/phuctm97/pdfvector/pull/222) [`3b78122`](https://github.com/phuctm97/pdfvector/commit/3b78122a35206b85be4ac61813ad1691ad57b866) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Re-trigger releases for client, instance-client, and gateway-server (previous attempt failed at frozen-lockfile install before publish)
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`3b78122`](https://github.com/phuctm97/pdfvector/commit/3b78122a35206b85be4ac61813ad1691ad57b866)]:
|
|
17
|
+
- @pdfvector/instance-client@0.0.44
|
|
18
|
+
|
|
19
|
+
## 0.0.23
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
- [#221](https://github.com/phuctm97/pdfvector/pull/221) [`84b9c58`](https://github.com/phuctm97/pdfvector/commit/84b9c58ce1a4f920e163f1666f738c83b3faa5c2) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Add typed PDFVectorError class hierarchy to instance-client SDK
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`84b9c58`](https://github.com/phuctm97/pdfvector/commit/84b9c58ce1a4f920e163f1666f738c83b3faa5c2)]:
|
|
27
|
+
- @pdfvector/instance-client@0.0.43
|
|
28
|
+
|
|
3
29
|
## 0.0.22
|
|
4
30
|
### Patch Changes
|
|
5
31
|
|
package/README.md
CHANGED
|
@@ -580,14 +580,12 @@ console.log(resultB.documentId); // "doc-b"
|
|
|
580
580
|
|
|
581
581
|
## Error Handling
|
|
582
582
|
|
|
583
|
-
All API errors are thrown as `
|
|
583
|
+
All API errors are thrown as `PDFVectorError` instances. The SDK transparently maps every server error into the most specific subclass it can, so you can branch on the type using `instanceof` and read typed metadata fields directly.
|
|
584
584
|
|
|
585
585
|
```typescript
|
|
586
|
-
import { createClient,
|
|
586
|
+
import { createClient, PDFVectorError } from "@pdfvector/client";
|
|
587
587
|
|
|
588
|
-
const client = createClient({
|
|
589
|
-
apiKey: "your-api-key",
|
|
590
|
-
});
|
|
588
|
+
const client = createClient({ apiKey: "your-api-key" });
|
|
591
589
|
|
|
592
590
|
try {
|
|
593
591
|
const result = await client.document.parse({
|
|
@@ -595,10 +593,12 @@ try {
|
|
|
595
593
|
});
|
|
596
594
|
console.log(result.markdown);
|
|
597
595
|
} catch (error) {
|
|
598
|
-
if (error instanceof
|
|
596
|
+
if (error instanceof PDFVectorError) {
|
|
599
597
|
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
600
598
|
console.error(`HTTP Status: ${error.status}`);
|
|
601
|
-
console.error(`
|
|
599
|
+
console.error(`Request ID: ${error.requestId}`); // server-assigned, useful for support
|
|
600
|
+
console.error(`Document ID: ${error.documentId}`); // echoed back if you set one
|
|
601
|
+
console.error(`User error: ${error.userError}`); // true if caused by your input
|
|
602
602
|
} else {
|
|
603
603
|
// Network errors (DNS, connection refused, timeout) bubble up as TypeError.
|
|
604
604
|
console.error("Unexpected Error:", error);
|
|
@@ -606,13 +606,62 @@ try {
|
|
|
606
606
|
}
|
|
607
607
|
```
|
|
608
608
|
|
|
609
|
-
|
|
609
|
+
### Branching on specific error types
|
|
610
|
+
|
|
611
|
+
Every error class extends `PDFVectorError`, so you can use `instanceof` to handle specific cases. Specialized subclasses expose typed fields pulled from the error's `data` payload:
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
import {
|
|
615
|
+
createClient,
|
|
616
|
+
FileTooLargeError,
|
|
617
|
+
PageLimitExceededError,
|
|
618
|
+
PasswordProtectedError,
|
|
619
|
+
URLFetchError,
|
|
620
|
+
UnauthorizedError,
|
|
621
|
+
TooManyRequestsError,
|
|
622
|
+
EmptyDocumentError,
|
|
623
|
+
ExtractionFailedError,
|
|
624
|
+
PDFVectorError,
|
|
625
|
+
} from "@pdfvector/client";
|
|
626
|
+
|
|
627
|
+
try {
|
|
628
|
+
await client.document.parse({ url: "...", model: "nano" });
|
|
629
|
+
} catch (error) {
|
|
630
|
+
if (error instanceof FileTooLargeError) {
|
|
631
|
+
console.error(
|
|
632
|
+
`File ${error.fileSizeMB}MB exceeds ${error.limitMB}MB limit for the '${error.model}' model`,
|
|
633
|
+
);
|
|
634
|
+
} else if (error instanceof PageLimitExceededError) {
|
|
635
|
+
console.error(
|
|
636
|
+
`Document has ${error.pageCount} pages — ${error.model} only supports up to ${error.pageLimit}`,
|
|
637
|
+
);
|
|
638
|
+
} else if (error instanceof PasswordProtectedError) {
|
|
639
|
+
console.error("Remove the password from the file and try again");
|
|
640
|
+
} else if (error instanceof URLFetchError) {
|
|
641
|
+
console.error(`Could not fetch ${error.url}: ${error.statusCode} ${error.statusText}`);
|
|
642
|
+
} else if (error instanceof UnauthorizedError) {
|
|
643
|
+
console.error("Invalid API key — check your dashboard");
|
|
644
|
+
} else if (error instanceof TooManyRequestsError) {
|
|
645
|
+
console.error(`Rate limit ${error.limit} exceeded; resets at ${error.resetAt}`);
|
|
646
|
+
} else if (error instanceof EmptyDocumentError) {
|
|
647
|
+
console.error("The document has no readable content");
|
|
648
|
+
} else if (error instanceof ExtractionFailedError) {
|
|
649
|
+
console.error(`Extraction failed. Hint: ${error.hint}`);
|
|
650
|
+
if (error.rawText) console.error(`Model output sample: ${error.rawText}`);
|
|
651
|
+
} else if (error instanceof PDFVectorError) {
|
|
652
|
+
// Catch-all for any error code not specifically handled
|
|
653
|
+
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
You can also branch on the error code if you prefer:
|
|
610
659
|
|
|
611
660
|
```typescript
|
|
612
661
|
try {
|
|
613
662
|
await client.document.parse({ url: "..." });
|
|
614
663
|
} catch (error) {
|
|
615
|
-
if (error instanceof
|
|
664
|
+
if (error instanceof PDFVectorError) {
|
|
616
665
|
switch (error.code) {
|
|
617
666
|
case "UNAUTHORIZED":
|
|
618
667
|
console.error("Invalid API key");
|
|
@@ -620,23 +669,83 @@ try {
|
|
|
620
669
|
case "BAD_REQUEST":
|
|
621
670
|
console.error("Validation error:", error.message);
|
|
622
671
|
break;
|
|
672
|
+
case "UNPROCESSABLE_CONTENT":
|
|
673
|
+
console.error("Could not process document:", error.message);
|
|
674
|
+
break;
|
|
623
675
|
case "INTERNAL_SERVER_ERROR":
|
|
624
|
-
console.error(
|
|
676
|
+
console.error(`Server error (requestId: ${error.requestId}):`, error.message);
|
|
625
677
|
break;
|
|
626
678
|
}
|
|
627
679
|
}
|
|
628
680
|
}
|
|
629
681
|
```
|
|
630
682
|
|
|
683
|
+
### Error Class Hierarchy
|
|
684
|
+
|
|
685
|
+
```
|
|
686
|
+
PDFVectorError
|
|
687
|
+
├── BadRequestError (400)
|
|
688
|
+
│ ├── FileTooLargeError — fileSizeMB, limitMB, model
|
|
689
|
+
│ ├── PageLimitExceededError — pageCount, pageLimit, model
|
|
690
|
+
│ ├── PasswordProtectedError
|
|
691
|
+
│ ├── UnsupportedFormatError — format, supportedFormats
|
|
692
|
+
│ ├── URLFetchError — url, statusCode, statusText
|
|
693
|
+
│ ├── TierNotSupportedError — documentType, model, allowedTypes
|
|
694
|
+
│ ├── InvalidSchemaError — reason
|
|
695
|
+
│ └── NoInputProvidedError
|
|
696
|
+
├── UnauthorizedError (401)
|
|
697
|
+
├── NotFoundError (404)
|
|
698
|
+
├── ConflictError (409)
|
|
699
|
+
├── TooManyRequestsError (429) — limit, resetAt
|
|
700
|
+
├── UnprocessableContentError (422)
|
|
701
|
+
│ ├── EmptyDocumentError
|
|
702
|
+
│ ├── NoTextDetectedError
|
|
703
|
+
│ └── ExtractionFailedError — hint, rawText
|
|
704
|
+
├── InternalServerError (500)
|
|
705
|
+
└── NotImplementedError (501)
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
### Common fields on every `PDFVectorError`
|
|
709
|
+
|
|
710
|
+
| Field | Type | Description |
|
|
711
|
+
|-------|------|-------------|
|
|
712
|
+
| `code` | `string` | The ORPC error code (`BAD_REQUEST`, `UNAUTHORIZED`, etc.) |
|
|
713
|
+
| `status` | `number` | HTTP status code (400, 401, 404, 409, 422, 429, 500, 501) |
|
|
714
|
+
| `message` | `string` | Human-readable error message |
|
|
715
|
+
| `data` | `Record<string, unknown>` | Raw error payload from the server |
|
|
716
|
+
| `requestId` | `number \| undefined` | Server-assigned request ID — include in support tickets |
|
|
717
|
+
| `documentId` | `string \| undefined` | Echoed back if you passed `context.documentId` |
|
|
718
|
+
| `userError` | `boolean` | `true` if the failure was caused by your input (vs. a server-side issue) |
|
|
719
|
+
| `cause` | `unknown` | Original error (the underlying `ORPCError` from the wire) |
|
|
720
|
+
|
|
721
|
+
### Type guard
|
|
722
|
+
|
|
723
|
+
If you'd rather not import `PDFVectorError` just to do an `instanceof` check, use the `isPDFVectorError` guard:
|
|
724
|
+
|
|
725
|
+
```typescript
|
|
726
|
+
import { isPDFVectorError } from "@pdfvector/client";
|
|
727
|
+
|
|
728
|
+
try {
|
|
729
|
+
await client.document.parse({ url: "..." });
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (isPDFVectorError(error)) {
|
|
732
|
+
console.error(error.code, error.message, error.requestId);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
```
|
|
736
|
+
|
|
631
737
|
### Error Codes
|
|
632
738
|
|
|
633
739
|
| Code | Status | Description |
|
|
634
740
|
|------|--------|-------------|
|
|
635
|
-
| `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL,
|
|
741
|
+
| `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL, file too large, page limit exceeded, invalid JSON Schema) |
|
|
636
742
|
| `UNAUTHORIZED` | 401 | Missing or invalid API key |
|
|
637
|
-
| `
|
|
743
|
+
| `NOT_FOUND` | 404 | Resource not found (e.g., academic paper ID, version) |
|
|
744
|
+
| `CONFLICT` | 409 | Operation conflicts with the current state |
|
|
745
|
+
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed (empty, no readable text, extraction failed) |
|
|
638
746
|
| `TOO_MANY_REQUESTS` | 429 | Rate limit exceeded |
|
|
639
|
-
| `INTERNAL_SERVER_ERROR` | 500 | Server-side failure |
|
|
747
|
+
| `INTERNAL_SERVER_ERROR` | 500 | Server-side failure — capture the `requestId` for support |
|
|
748
|
+
| `NOT_IMPLEMENTED` | 501 | Endpoint not available on this instance |
|
|
640
749
|
|
|
641
750
|
## TypeScript Support
|
|
642
751
|
|
|
@@ -645,6 +754,31 @@ The SDK is written in TypeScript and includes full type definitions:
|
|
|
645
754
|
```typescript
|
|
646
755
|
import {
|
|
647
756
|
createClient,
|
|
757
|
+
isPDFVectorError,
|
|
758
|
+
// Base error class — all errors inherit from this
|
|
759
|
+
PDFVectorError,
|
|
760
|
+
// HTTP-aligned error categories
|
|
761
|
+
BadRequestError,
|
|
762
|
+
UnauthorizedError,
|
|
763
|
+
NotFoundError,
|
|
764
|
+
ConflictError,
|
|
765
|
+
TooManyRequestsError,
|
|
766
|
+
UnprocessableContentError,
|
|
767
|
+
InternalServerError,
|
|
768
|
+
NotImplementedError,
|
|
769
|
+
// Specialized error subclasses with typed metadata
|
|
770
|
+
FileTooLargeError,
|
|
771
|
+
PageLimitExceededError,
|
|
772
|
+
PasswordProtectedError,
|
|
773
|
+
UnsupportedFormatError,
|
|
774
|
+
URLFetchError,
|
|
775
|
+
TierNotSupportedError,
|
|
776
|
+
InvalidSchemaError,
|
|
777
|
+
NoInputProvidedError,
|
|
778
|
+
EmptyDocumentError,
|
|
779
|
+
NoTextDetectedError,
|
|
780
|
+
ExtractionFailedError,
|
|
781
|
+
// Underlying ORPC error — re-exported for advanced use cases
|
|
648
782
|
ORPCError,
|
|
649
783
|
} from "@pdfvector/client";
|
|
650
784
|
|
|
@@ -655,6 +789,7 @@ import type {
|
|
|
655
789
|
ContractInputs,
|
|
656
790
|
ContractOutputs,
|
|
657
791
|
PDFVectorModel,
|
|
792
|
+
PDFVectorErrorCode,
|
|
658
793
|
} from "@pdfvector/client";
|
|
659
794
|
```
|
|
660
795
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfvector/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
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.45"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
".tsc",
|