Troubleshooting and tracing

Updated at:

This topic describes how to troubleshoot and resolve issues when you use the HarmonyOS SDK.

Log outputs

hilog outputs

The SDK provides hilog log outputs. When you develop in a local environment, view the logs in your development tool. The following code provides an example:

import { httpdns } from '@aliyun/httpdns';

httpdns.enableHiLog();

After you enable hilog log outputs, the SDK outputs relevant logs when you call SDK APIs. This helps you check the network request status of the SDK. The following log provides an example:

04-16 00:10:01.201   12063-12063  A08000/100000                  com.aliyu...dns.demo  I     asyncResolve www.aliyun.com 3 begin
04-16 00:10:01.202   12063-12063  A08000/Http                    com.aliyu...dns.demo  I     http://[2401:b180:2000:30::1c]/100000/d?host=www.aliyun.com&query=6&sid=4vkjAaOpeRXn&sdk=harmony_0.0.0 begin
04-16 00:10:01.281   12063-12063  A08000/Http                    com.aliyu...dns.demo  I     http://[2401:b180:2000:30::1c]/100000/d?host=www.aliyun.com&query=6&sid=4vkjAaOpeRXn&sdk=harmony_0.0.0 success {"host":"www.aliyun.com","ttl":30,"origin_ttl":30,"client_ip":"2401:b180:8000:1:e0e3:8b81:e0e3:8b81","ipsv6":["2401:b180:1:60:0:0:0:5","2401:b180:1:60:0:0:0:6"]}
04-16 00:10:01.281   12063-12063  A08000/100000                  com.aliyu...dns.demo  I     asyncResolve www.aliyun.com 3 end {"host":"www.aliyun.com","hasResult":true,"valid":true,"ipv6s":["2401:b180:1:60:0:0:0:5","2401:b180:1:60:0:0:0:6"]}

The URL http://[2401:b180:2000:30::1c]/100000/d?host=www.aliyun.com&query=6&sid=4vkjAaOpeRXn&sdk=harmony_0.0.0 is a request sent by the SDK. For more information about the request protocol, see Resolve a single domain name.

Online log collection

The SDK provides a log registration API that helps you integrate log collection system into your application. The following code provides an example:

import { httpdns, ILogger } from '@aliyun/httpdns';
import hilog from '@ohos.hilog';

class AppLogger implements ILogger {
  log(level: hilog.LogLevel, msg: string): void {
    // Receive logs in the log system.
    // By default, collect logs of hilog.LogLevel.ERROR and higher.
  }
}

const appLogger = new AppLogger();

httpdns.addLogger(appLogger);

In a production environment, we recommend that you collect logs with a level of hilog.LogLevel.ERROR or higher, or use a proactive switch policy to control when to collect logs.

Troubleshoot "RESOLVE FAIL" logs

For SDK 1.2.1 and later, when domain name resolution fails, the SDK prints a log message in the format of "RESOLVE FAIL, Host:xxx, Query:xxx Msg:xxx". You can search for logs that have the "RESOLVE FAIL" prefix to identify the cause of the failure. The following logs provide examples:

Invalid signature:

04-11 11:04:58.443   14509-14509   A08000/100000     com.aliyu...lication  W     RESOLVE FAIL, Host:www.aliyun.com, Query:4 Msg:HTTPDNS_102: InvalidSignature 

Expired signature:

04-11 13:41:20.380   2316-2316   A08000/100000     com.aliyu...ns.demo2  W     RESOLVE FAIL, Host:www.aliyun.com, Query:4,6 Msg:HTTPDNS_102: SignatureExpired 

Network error:

04-11 14:39:57.532   2316-2316   A08000/100000     com.aliyu...ns.demo2  W     RESOLVE FAIL, Host:www.aliyun.com, Query:6 Msg:HTTPDNS_101: Request failed,{"code":2300007,"message":"Couldn't connect to server"} 

Domain name not configured in the console:

04-11 15:53:16.623   23160-23160  A08000/ResolveService      com.aliyu...ns.demo2  W     RESOLVE FAIL, Host:www.aliyun.com, Query:4 Msg:NonWhitelistDomain

In the preceding log, "RESOLVE FAIL, Host:www.aliyun.com, Query:4 Msg:HTTPDNS_102: InvalidSignature" is the resolution failure log message. Host indicates the domain name to resolve. Query indicates the IP address type to resolve. Msg indicates the error message for the failure.

Backend troubleshooting

Get the sessionId

Work with the HTTPDNS service team to troubleshoot issues that are difficult to diagnose. The SDK provides a sessionId field. Each time the SDK sends a resolution request to the service, it includes the sessionId. Therefore, when an issue occurs, retrieve the sessionId. This helps the HTTPDNS team find the relevant resolution request. To retrieve the sessionId, perform the following steps:

import { httpdns, HttpDnsError } from '@aliyun/httpdns';
import hilog from '@ohos.hilog';

const ACCOUNT_ID = 'Replace this with the Account ID from the Alibaba Cloud HTTPDNS console';

httpdns.getService(ACCOUNT_ID).then((service) => {
  // ************* Get sessionId: start *************
  const sessionId = service.getSessionId();
  // ************* Get sessionId: end *************
  console.log(`sessionId is ${sessionId}`);
}).catch((e: HttpDnsError) => {
  console.error(`Failed ${e.code} ${e.message}`);
});

If a resolution error occurs, provide this information when you seek technical support through DingTalk groups or tickets.

Note

The sessionId is randomly generated, is 12 characters long, and remains unchanged throughout the application lifecycle.

Error codes

When an error occurs, the SDK APIs throw an HttpDnsError. This error contains the code and message fields for you to identify the cause of an error.

Error code

Error message

Solution

Notes

HTTPDNS_000

System error

View the specific error message, which contains the system error code.

This error occurs when a system API reports an error during a call.

HTTPDNS_001

Internal error

Submit the specific error message to EMAS for troubleshooting.

This error occurs when an unexpected error occurs in the SDK.

HTTPDNS_002

Unknown error

Submit the specific error message to EMAS for troubleshooting.

This error occurs when an unexpected error occurs in the SDK.

HTTPDNS_003

Service disabled

Contact EMAS to confirm whether your account status is Normal.

HTTPDNS_004

Frequent requests

No action is required.

This error occurs when requests continuously fail due to poor network conditions. The SDK limits the request frequency to avoid affecting application performance.

HTTPDNS_005

An SDns request must contain the cacheKey parameter.

Check whether the cacheKey parameter for software-defined DNS is passed correctly.

HTTPDNS_006

The key of an SDns parameter can contain only letters, digits, hyphens (-), and underscores (_).

Check whether the parameters for software-defined DNS meet the requirements.

HTTPDNS_007

The value of an SDns parameter after encoding can contain only letters, digits, hyphens (-), and underscores (_).

Check whether the parameter values for software-defined DNS meet the requirements.

HTTPDNS_008

The SDns parameter is too long.

The serialized parameters for software-defined DNS cannot exceed 1,000 characters. Shorten the parameters.

HTTPDNS_100

Request failed

Submit the specific error message to EMAS for troubleshooting.

The HTTPDNS service returns an HTTP status code other than 200.

HTTPDNS_101

Request failed

No action is required.

Network timeout or disconnection. The SDK has built-in mechanisms, such as retry, to reduce the probability of such errors.

HTTPDNS_102

Service error

For more information, see the list of error codes.

HTTPDNS_200

The DB cannot be used because Context is not configured.

Check whether the context field is missing from the SDK initialization configuration.

HTTPDNS_201

Failed to retrieve the DB.

View the specific error message for troubleshooting.

An error occurred when retrieving the database.

HTTPDNS_202

Failed to read the DB.

View the specific error message for troubleshooting.

An error occurred when reading the database.

HTTPDNS_203

Failed to save the DB.

View the specific error message for troubleshooting.

An error occurred when saving the database.

HTTPDNS_204

Failed to purge the DB.

View the specific error message for troubleshooting.

An error occurred when purging the database.

HTTPDNS_205

Failed to retrieve the configuration storage.

View the specific error message for troubleshooting.

An error occurred during getPreferencesSync.

HTTPDNS_206

Failed to read the configuration storage.

View the specific error message for troubleshooting.

An error occurred when reading the configuration.

HTTPDNS_207

Failed to write to the configuration storage.

View the specific error message for troubleshooting.

An error occurred when writing the configuration.