Error Handling
Handle Embed SDK errors by passing an onError callback to SevenEmbed.render(). The SDK reports both widget-level and SDK-level errors through the same callback. Use the error code to decide whether to retry, request a new token, or correct your configuration.
Adding an error callback
SevenEmbed.render({
target: '#7shifts-dashboard',
token: 'ACCESS_TOKEN_FROM_YOUR_BACKEND',
companyGuid: 'YOUR_COMPANY_GUID',
components: ['salesLabor'],
onError: function (error) {
if (error.code === 'TOKEN_EXPIRED') {
// Request a new access token from your backend, then re-render the SDK.
console.error('The access token expired. Request a new token.');
return;
}
console.error('Embed SDK error:', error);
}
});Error object
Every error passed to onError has the following shape:
{
"widget": "salesLabor",
"status": 401,
"message": "The resource owner or authorization server denied the request.",
"code": "TOKEN_EXPIRED"
}| Field | Type | Description |
|---|---|---|
widget | string | Widget that triggered the error, or global for SDK-level errors. |
status | integer | HTTP status code. Network errors use 0. |
message | string | Human-readable error description. |
code | string | Machine-readable error code. Use this to drive error handling logic. |
Error codes
| Code | HTTP status | Meaning | Recommended action |
|---|---|---|---|
TOKEN_EXPIRED | 401 | Access token is invalid or expired. | Generate a new token from your backend and re-initialize the SDK. |
FORBIDDEN | 403 | Token lacks required scopes. | Verify the scopes requested during OAuth. |
NOT_FOUND | 404 | Requested resource was not found. | Verify companyGuid and locationId. |
SERVER_ERROR | 5xx | 7shifts returned a server error. | Retry after a delay. |
NETWORK_ERROR | 0 | The browser could not reach the API. | Check connectivity and retry. |
CONFIG_ERROR | — | SDK configuration is invalid. | Check required fields: target, token, and companyGuid. |
Updated 1 day ago
