For Developers
Error Handling
The Edlink TypeScript SDK provides a custom Error type that matches the structure of error responses from the Edlink API. There are, however, different places where they can occur.
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
There are a few ways to perform error handling with an async generator. You can see two common patterns below.
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
});