Documentation
Search…
Handling Errors
Provide feedback to your users when something goes wrong.
In order to display an error to your user, your server may respond with a 4xx or 5xx HTTP response code, and an application/json payload containing an error.
To display a single error message to your user, respond with a payload in the following format
1
{
2
error: 'An error message',
3
}
Copied!
If your server does respond with an error payload, a generic error message will be displayed. To perform your own error handling, or provide a custom error message, you may provide an onError callback function to your feature.
1
import React from 'react';
2
import { Canvas } from '@mason-api/react-sdk';
3
4
class MyRegister extends React.Component {
5
render() {
6
return <Canvas id="YOUR_COMPONENT_ID" onError={(response) => {
7
let error = '';
8
for (const key in response) {
9
error += response[key] + '\n';
10
}
11
return error;
12
}} />;
13
}
14
}
Copied!

Handling Errors in HTML

Handle errors in HTML by subscribing to the mason.error event.
1
<mason-canvas id="register" data-id="YOUR_COMPONENT_ID"></mason-canvas>
2
<script type="text/javascript">
3
const registerNode = document.getElementById('register');
4
registerNode.addEventListener('mason.error', function(event) {
5
const error = event.detail;
6
//do something with error
7
});
8
</script>
Copied!
Copy link