For Developers
Error Handling
The Edlink SDK will throw an error if the API returns an error response.
Single Request Error Handling
The SDK will propigate the error to the caller. The caller can catch the error and handle it as needed. The error object will contain the following properties from the API response:
code
- The error codemessage
- The error messagestatus
- The HTTP status codeerrors
- An array of other errors
edlink
.use(token_set)
.schools.fetch('14e9c28a-aa22-4a4b-b54b-8c6df61701fe')
.catch((error) => {
console.log(error.code); // NOT_FOUND
console.log(error.message); // School with id 14e9c28a-aa22-4a4b-b54b-8c6df61701fe not found for this integration.
console.log(error.status); // 400
});
Generator Error Handling {generator-error-handling}
There are a few ways to perform error handling with an async generator. To name two.
A try/catch block:
try {
for await (const school of edlink.use(token_set).schools.list()) {
// business logic here
}
} catch (error) {
// handle error
}
A wrapper function:
const paginate = async () => {
for await (const school of edlink.use(token_set).schools.list()) {
// business logic here
}
};
paginate().catch((error) => {
// handle error
});