mindee-api-nodejs icon indicating copy to clipboard operation
mindee-api-nodejs copied to clipboard

Node.js client throwing an error while API return Plan limit has been reached error

Open ppinel opened this issue 1 year ago • 2 comments

Prerequisites

Put an X between the brackets on this line if you have done all of the following:

  • [x] Reproduced the problem or exposed a new need
  • [x] Checked the github existing issues

Description

Hello, An error is thrown when API return Plan limit has been reached

error: TypeError: Cannot read properties of undefined (reading 'ocr')
       at new Document (/workflow/node_modules/.pnpm/[email protected]/node_modules/mindee/src/parsing/common/document.js:20:33)
       at new PredictResponse (/workflow/node_modules/.pnpm/[email protected]/node_modules/mindee/src/parsing/common/predictResponse.js:19:25)
       at Client.parse (/workflow/node_modules/.pnpm/[email protected]/node_modules/mindee/src/client.js:67:16)
       at processTicksAndRejections (node:internal/process/task_queues:95:5)
       at async /workflow/workers/src/activities/mindee/processInvoice.ts:32:20
       at async Activity.execute (/workflow/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/worker/src/activity.ts:117:14)
       at async /workflow/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/worker/src/activity.ts:144:24
       at async /workflow/node_modules/.pnpm/@[email protected]/node_modules/@temporalio/worker/src/worker.ts:974:24 

I initilaized the Mindee client to not throw, instead return an error.

const inputSource = mindee.docFromStream(stream, filename);
const result = await mindee.parse(product.InvoiceV4, inputSource);

Steps to Reproduce

  1. Have an account with API usage limit reached
  2. Initialise the client api to not throw (I don't if this one change anything to the behaviour)
  3. Call the API to process an invoice

Expected behavior:

Client should not through, instead return an error with proper error code as mentioned in documentation.

Actual behavior:

An error is thrown saying : TypeError: Cannot read properties of undefined (reading 'ocr') It shouldn't be trying to process the API response while having an error returned.

Reproduces how often:

Every time

Versions

npm list | grep mindee
├── [email protected] -> ./../node_modules/.pnpm/[email protected]/node_modules/mindee

Testing on Mac OS 14.1.1 Using Node.js v20.9.0

Additional Information

ppinel avatar Apr 05 '24 08:04 ppinel

This issue arises from the implementation of throwOnError, which is currently malfunctioning due to significant changes made since its initial implementation. It is planned to undergo substantial refactoring in the future and will be deprecated in the next release. In the meantime, I advise all users attempting to utilize the throwOnError parameter to instead handle the relevant exceptions using catch.

sebastianMindee avatar Apr 10 '24 13:04 sebastianMindee

Update: while not addressing the throwOnError problem directly, some error displays similar to this one should be fixed in #267.

Also, for the sake of visibility I will keep this opened until we fully fix the throwOnError incompatibility.

sebastianMindee avatar Apr 12 '24 14:04 sebastianMindee