#community-help

Troubleshooting Typesense Errors in NestJS Project

TLDR Iulian is experiencing Typesense errors in a NestJS project. Kishore Nallan and Jason provide advice, suggesting try-catch and looking at code snippets respectively.

Powered by Struct AI

1

Nov 26, 2021 (26 months ago)
Iulian
Photo of md5-790da83a2e75e1863cd6e991ddc09073
Iulian
10:57 AM
Hi! A while ago I noticed TypeSense errors are taking down my NestJS project unless I restart it despite the calls being wrapped in a try-catch. Here's a log, because I couldn't provide one last time

main | /app/node_modules/typesense/lib/Typesense/Typesense/ApiCall.js:261
main | const customErrror = new CustomErrorKlass(errorMessage)
main | ^
main | Error: Request failed with HTTP code 400 | Server said: Field stationId has been declared in the schema, but is not found in the document.
main | at ApiCall._customErrorForResponse (/app/node_modules/typesense/lib/Typesense/Typesense/ApiCall.js:261:26)
main | at ApiCall._callee$ (/app/node_modules/typesense/lib/Typesense/Typesense/ApiCall.js:137:38)
main | at tryCatch (/app/node_modules/regenerator-runtime/runtime.js:63:40)
main | at Generator.invoke [as _invoke] (/app/node_modules/regenerator-runtime/runtime.js:294:22)
main | at Generator.next (/app/node_modules/regenerator-runtime/runtime.js:119:21)
main | at asyncGeneratorStep (/app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
main | at _next (/app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:04 AM
Jason will be able to take a look into what's happening here, but wrapping Typesense API call inside a try{} and a blanket catch should catch all the errors.

As for the actual reason for this error, a document without the stationId field is being attempted to be added.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:47 PM
Thanks Iulian. Could you also share the code snippet that calls this Typesense client method?
Dec 16, 2021 (25 months ago)
Iulian
Photo of md5-790da83a2e75e1863cd6e991ddc09073
Iulian
06:38 PM
Hi! Sorry I forgot about this... This is the snippet:
createPost(data: TypeSensePost) {
try {
typeSenseClient.collections('posts').documents().create(data);
} catch (error) {
console.log(error);
}
}

1