Exception Handling
Use Bringg Dispatcher SDK exception handling to customize Bringg for your own system.
Exception Handling and the Promise Pattern
The Bringg Dispatcher SDK uses the promise design pattern and a decorator factory for handling exceptions. You can chain the results of your callbacks using a then and catch to implement your own error handling using the exception messages. You can also use the Bringg Dispatcher SDK Logger to customize logging various levels of log messages in your own implementation.
Chaining a Callback for Exception Handling
Syntax
bringgDashboardSDK..then().catch();
Example
The following HTML with JavaScript example executes initWithEmail to initialize a session, and then users.get() to get the user details for a user with the Id "1".
If users.get() succeeds, the callback to then executes its function generating an alert. If users.get() fails, the callback to catch writes the exception message to the console.
<!doctype html>
<html lang="en">
<head>
<!-- ... -->
<script src="bringg-dashboard-sdk.js"></script>
</head>
<body>
<!-- ... -->
<script>
BringgDashboardSDK.initWithEmail("[email protected]", "XXXXXXXX").then(bringgDashboardSDK => {
bringgDashboardSDK.users.get(1).then(function (myUserData) {
alert(JSON.stringify("The driver " + myUserData.name + " (Bringg Id: " + myUserData.id + ") is currently " + myUserData.status));
}).catch(console.error);
});
</script>
</body>
</html>
Delegating the Logger
You can optionally delegate the Bringg Dispatcher SDK Logger to customize your implementation with your own functionality for any of the following log levels:
- log - log everything
- error - log errors and fatal errors
- warn - log warnings, errors, and fatal errors
- info - log informational messages, warnings, errors, and fatal errors
- debug - log debugging and informational messages, warnings, errors, and fatal errors
Syntax
BringgDashboardSDK.delegateLogger({:, :, ...);
where
- is log, error, warn, info, or debug
- is your own functionality
Example
The following sends warnings, error messages, and fatal error messages to the console.
<!doctype html>
<html lang="en">
<head>
<!-- ... -->
<script src="bringg-dashboard-sdk.js"></script>
</head>
<body>
<!-- ... -->
<script>
BringgDashboardSDK.delegateLogger({warn:console.log});
BringgDashboardSDK.initWithEmail("[email protected]", "XXXXXXXX").then(bringgDashboardSDK => {
bringgDashboardSDK.users.get(1).then(function (myUserData) {
alert(JSON.stringify("The driver " + myUserData.name + " (Bringg Id: " + myUserData.id + ") is currently " + myUserData.status));
}).catch(console.error);
});
</script>
</body>
</html>
Updated over 6 years ago