Skip to content

Handling Errors

The Metronome API has strict input data checking. When the service cannot validate the input data, it will respond with specific information regarding which fields are incorrect, missing, or which contain invalid information. These are called schema validation errors. It is also possible to make other errors, such as using a key which does not have the correct API permissions, which will receive an authorisation error.

You might consider describing errors from Metronome in the following way. This code will be considered included in the following examples.

errors.ts
import { ApiException, ValidationError, ValidationProblem } from "@privatedataservices/metronome-client";
export const explainError = (err: any) => {
if (err instanceof ApiException) {
err.body.errors.forEach( (error: any, errorIndex: number) => {
if(error instanceof String)
console.error("Error %s: ", errorIndex, error);
else {
var validationError = error as ValidationError;
console.error(" Error %s is a validation error.The server side spec that failed to match is '%s' and the request received from this client at the server was: %s", errorIndex, validationError.spec, JSON.stringify(validationError.requestFromClient));
validationError.problems.forEach( (problem: ValidationProblem) => {
console.log(" Problem location: %s", problem.location.join(", "));
console.log(" Problem value: %s", problem.val);
console.log(" Problem description: %s", problem.description);
});
}
});
} else {
console.error("Non-API exception:", err);
}
}