1

I have some json schemas in a folder ..src/schema/jsonschemas And I have my node js scripts in a folder ../src/nodescripts/script.js

let Ajv = require('ajv');
let ajv = new Ajv();
jschema = JSON.parse(fs.readFileSync("../src/schema/file.json", 'utf8'));
let validate = ajv.compile(jschema);

But i get the following error: UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2). The cause is the $ref on the json schema(but i ndeed the $ref part. Any Ideas?

Sken
  • 59
  • 1
  • 1
  • 5
  • Possible duplicate of [What is an unhandled promise rejection?](https://stackoverflow.com/questions/40500490/what-is-an-unhandled-promise-rejection) – Guilherme Martin Oct 23 '19 at 16:15
  • @GuilhermeMartin its not a duplicate because the error or warning occurs because of the ajv.compile because i am using a $ref in a thoer folder that the ajv cant resolve. the link you posted has nothing to do with my problem... – Sken Oct 23 '19 at 16:19
  • in python we have something like from jsonschema import RefResolver resolver = RefResolver("...", None). Is there something for node js to? – Sken Oct 23 '19 at 16:30
  • @Sken How do you know the cause of the error is the $ref in your schema? Can you wrap this section of your code in a try/catch and share the error message with us? – Justin Moser Oct 23 '19 at 16:43
  • @JustinMoser because when i delete the $ref then it works. – Sken Oct 23 '19 at 17:13

0 Answers0