Errors, Logging & Cleanup
BlynkBridgeError
Every request method rejects with a BlynkBridgeError, exposed on window by both hosts:
class BlynkBridgeError extends Error {
name: 'BlynkBridgeError';
code: string; // stable, machine-readable — branch on this
message: string; // human-readable — can change, never branch on it
details: object; // extra context, e.g. { index, count } or { selector, indexes }
}try {
await bridge.getDeviceMetadata({ id: 42 });
} catch (error) {
if (error instanceof window.BlynkBridgeError) {
bridge.log(error.code + ' ' + JSON.stringify(error.details));
}
}
// A tolerant helper for catch blocks
const codeOf = (error) => (error && typeof error.code === 'string') ? error.code : 'unknown';Codes shared by every request
device_unavailable
Called outside a Blynk host, or the host lacks that bridge
bridge_destroyed
Called after destroy()
invalid_request
Arguments failed validation
request_timeout
No answer in time — see below
server_error
The host failed without a specific code
Each method's own codes are listed in its entry.
Errors usually arrive twice. Every failing request reports its message through sendError — so your onError runs — before the Promise rejects. In .catch(), update widget state only ("--", "Could not load data"); don't show a second message. The Promise still rejects when error notifications are disabled.
Request timeouts (web)
getDeviceInfo, getTheme, getUnitSystems, isPermissionAllowed, storage, native screens
10 s
getHistoricalData, getMapData, events, device metadata, getDeviceTags, file and asset lists, records and deletes
30 s
executeDataEngineQuery
35 s
getDeviceFileBlob, getAssetBlob, uploadDeviceFile
120 s
On mobile, history and map data also time out after 30 seconds and Data Engine queries after 35 seconds. Other mobile requests are bounded by the app.
Report an error
Shows an error in the host UI and passes it to your own
onError.
message
string
yes
Non-empty error message
Web: the message is posted to the dashboard, which shows it as the widget's runtime error.
Mobile: the app shows it as a toast.
It does nothing when
messageis empty or not a string, or whenisOnErrorEnabledisfalse.
Turn error reporting on or off
Suppresses or re-enables both
sendError()and theonErrorcallback.
enabled
boolean
yes
false silences error reporting; true (default) re-enables it
Log a message
Forwards a message to the Blynk platform logger.
setLogging(false) turns off logging only, not error delivery.
Destroy the bridge
Detaches the bridge when your UI is removed.
Clears all six callbacks and removes the host handlers this instance owns (on mobile, the
window.blynk*functions it installed).Afterwards every Promise-returning method rejects with
bridge_destroyed, andsendValue,sendErrorand dashboard-page navigation do nothing. Create a newBlynkBridgeto use the bridge again.Repeated calls are safe, and destroying an old instance doesn't disturb a newer one's handlers.
It doesn't abort requests or writes already in flight.
Use
setCallbacksto change handlers anddestroy()when your UI goes away — never replace the bridge globals by hand.
Was this helpful?

