Skip to content

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 ​

java
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:

DigitsMeaningDescription
Digits 1-2Level-1 categoryIdentifies the major category of the API (e.g., Device, Network)
Digits 3-4Level-2 categoryIdentifies the specific functional module under the major category (e.g., NFC, Wi-Fi)
Digits 5-7Specific error typeIdentifies 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

    • 00 General basic errors
    • 03 Update
    • 09 Encryption
  • 06 - Network

    • 00 General network errors
    • 02 Making requests
    • 03 Download
    • 04 Upload
    • 06 mDNS
  • 07 - Payment

    • 00 General payment errors
    • 01 Payment default level-2 category
  • 11 - Media

    • 07 Real-time audio/video
  • 13 - File

    • 00 General file errors
    • 01 File default level-2 category
    • 02 fd interface
  • 14 - Open interfaces

    • 16 Video account
  • 15 - Device

    • 00 General device errors
    • 04 NFC
    • 05 Wi-Fi
    • 09 Bluetooth Low Energy
    • 10 Bluetooth
  • 20 - AI

    • 02 Face 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:

java
"err":
{
  "errMsg": "openBluetoothAdapter:fail:not available",
  "errCode": 10001,
  "errno": 1500102
}

You can handle the exception with the following code:

java
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.

errnoerrMsgMeaning
0okSuccess
1cancelCancelled
3system permission deniedSystem permission not granted to OpenPaas