Errno Error Codes
When using certain APIs/components, the Error object thrown in the exception (fail callback / Promise reject) carries a general error code errno in addition to errMsg.
Code Example
sud.openBluetoothAdapter({
success (res) {
console.log(res)
}
fail (err) {
console.log(err.errno)
}
})OpenPaaS errno Error Code Specification
Error Code Design Rules
The errno error code is fixed at 7 digits, and its construction logic is as follows:
| Digits | Meaning | Description |
|---|---|---|
| Digits 1-2 | Level-1 category | Identifies the major category of the API (e.g., Device, Network) |
| Digits 3-4 | Level-2 category | Identifies the specific functional module under the major category (e.g., NFC, Wi-Fi) |
| Digits 5-7 | Specific error type | Identifies the specific cause of the error under that functional module |
Example analysis: Error code 1504003:
15: Level-1 category (Device)04: Level-2 category (NFC)003: Specific error type
Integrated Category Index
The API categories currently integrated into the errno system are distributed as follows:
00 - General error codes
01 - Basic
00General basic errors03Update09Encryption
06 - Network
00General network errors02Making requests03Download04Upload06mDNS
07 - Payment
00General payment errors01Payment default level-2 category
11 - Media
07Real-time audio/video
13 - File
00General file errors01File default level-2 category02fd interface
14 - Open interfaces
16Video account
15 - Device
00General device errors04NFC05Wi-Fi09Bluetooth Low Energy10Bluetooth
20 - AI
02Face recognition
Note: the names of level-1 and level-2 categories are usually consistent with the directory structure in the API documentation.
Best Practices
Taking the API interface openBluetoothAdapter as an example, when the Bluetooth adapter is unavailable, the Error object thrown by the openBluetoothAdapter interface is:
"err":
{
"errMsg": "openBluetoothAdapter:fail:not available",
"errCode": 10001,
"errno": 1500102
}You can handle the exception with the following code:
sud.openBluetoothAdapter({
success (res) {
console.log(res)
},
fail (err) {
// OpenPaas cannot use Bluetooth; guide the user to enable Bluetooth in system settings
if ( err.errno === 1500102 ) {
sud.showModal({
content: 'Bluetooth is unavailable. Please enable it in system settings'
})
}
}
})Error Code List
The following is a list of errno values.
| errno | errMsg | Meaning |
|---|---|---|
| 0 | ok | Success |
| 1 | cancel | Cancelled |
| 3 | system permission denied | System permission not granted to OpenPaas |
