-
Notifications
You must be signed in to change notification settings - Fork 33
Error Handling
Jens Balvig edited this page Jan 17, 2022
·
5 revisions
We added a custom error handler to the library, so that you can handle errors easier. You can handle errors two ways, through callbacks and through promises.
Let's check out both.
This is the way we recommend handling errors. Each error will contain things like name
, message
, statusCode
so that you can distinguish them easily.
Check out the following code example how error could be handled.
let postmark = require("postmark")
const accountToken = "xxxx-xxxxx-xxxx-xxxxx-xxxxxx"
let accountClient = new postmark.AccountClient(accountToken);
accountClient.getDomain(1).then(result => {
console.log(result);
}).catch(error => {
if (error instanceof postmark.Errors.UnknownError) {
console.log("Unkown Postmark error");
console.error(error)
};
if (error.name === 'ApiInputError') {
console.log(error.name);
}
});
Logic used with callbacks would be similar.
accountClient.getDomain(1, function (error, data) {
if (error instanceof postmark.Errors.UnknownError) {
console.log("Unkown Postmark error");
console.error(error)
}
if (error.name === 'ApiInputError') {
console.log(error.name);
}
});
For additional information about the capabilities of the Postmark API, see Postmark Developers Documentation.
- Overview
- Migration from older version
- Getting started
- Email sending
- Bounces
- Templates
- Templates Push
- Server
- Servers
- Message Streams
- Webhooks
- Messages
- Domains
- Sender Signatures
- Stats
- Trigger Inbound Rules
- Suppressions
- Data Removal
- Embedding images in emails
- Error Handling
- Handling Web Hooks
- Mocking requests
- Troubleshooting
- Known issues and how to resolve them