Exception handling

DNS

  • API Reference
    • API function release records
    • API Service Domain Name
    • Appendix
    • Common Headers and Error Responses
    • General Description
    • Interface Overview
    • Overview
    • Private DNS Related Interfaces
      • Add resolution record
      • Associate VPC
      • Create a PrivateZone
      • Delete PrivateZone
      • Delete resolution record
      • Disassociate VPC
      • Modify resolution record
      • Query details of a PrivateZone
      • Query PrivateZone list
      • Query resolution record list
      • Set Resolution Record Status
    • Public DNS Related Interfaces
      • Domain Name Related Interfaces
      • Line Group Related Interfaces
      • Resolution Records Related Interfaces
  • FAQs
    • General FAQs
  • Function Release Records
  • Operation guide
    • Identity and access management
    • Local DNS service
      • Add Private Zone
      • Add resolution record
      • Associate VPC
      • Delete Private Zone
      • Resolver
    • Public DNS service
      • Add domain name
      • Add resolution
      • Enable Resolution Service
      • Line Grouping Function
      • Manage Resolution
      • Resolution Line Selection
      • Upgrade Domain Name to Enterprise Edition Operation Guide
    • Resolution Logging Management
  • Product Description
    • Application scenarios
    • Product advantages
    • Product functions
    • Product overview
    • Usage restrictions
  • Product pricing
  • Quick Start
    • Activate Service
    • Use Resolution Service
  • SDK
    • Golang-SDK
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Private DNS
      • Version history
    • Java-SDK
      • Install the SDK Package
      • Overview
      • Private DNS
      • Public DNS
      • Version history
    • Python-SDK
      • Initialization
      • Install the SDK Package
      • Overview
      • Private DNS
      • Public DNS
      • Version history
  • Service Level Agreement (SLA)
    • Internal DNS Service Level Agreement SLA
    • Public DNS Service Level Agreement SLA
  • Typical Practices
    • Implement URL Forwarding via Nginx
    • Local IDC Interconnection with Cloud DNS Service via Resolver
    • Quickly Set Up Private Domain Name Resolution Service Using Terraform
All documents
menu
No results found, please re-enter

DNS

  • API Reference
    • API function release records
    • API Service Domain Name
    • Appendix
    • Common Headers and Error Responses
    • General Description
    • Interface Overview
    • Overview
    • Private DNS Related Interfaces
      • Add resolution record
      • Associate VPC
      • Create a PrivateZone
      • Delete PrivateZone
      • Delete resolution record
      • Disassociate VPC
      • Modify resolution record
      • Query details of a PrivateZone
      • Query PrivateZone list
      • Query resolution record list
      • Set Resolution Record Status
    • Public DNS Related Interfaces
      • Domain Name Related Interfaces
      • Line Group Related Interfaces
      • Resolution Records Related Interfaces
  • FAQs
    • General FAQs
  • Function Release Records
  • Operation guide
    • Identity and access management
    • Local DNS service
      • Add Private Zone
      • Add resolution record
      • Associate VPC
      • Delete Private Zone
      • Resolver
    • Public DNS service
      • Add domain name
      • Add resolution
      • Enable Resolution Service
      • Line Grouping Function
      • Manage Resolution
      • Resolution Line Selection
      • Upgrade Domain Name to Enterprise Edition Operation Guide
    • Resolution Logging Management
  • Product Description
    • Application scenarios
    • Product advantages
    • Product functions
    • Product overview
    • Usage restrictions
  • Product pricing
  • Quick Start
    • Activate Service
    • Use Resolution Service
  • SDK
    • Golang-SDK
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Private DNS
      • Version history
    • Java-SDK
      • Install the SDK Package
      • Overview
      • Private DNS
      • Public DNS
      • Version history
    • Python-SDK
      • Initialization
      • Install the SDK Package
      • Overview
      • Private DNS
      • Public DNS
      • Version history
  • Service Level Agreement (SLA)
    • Internal DNS Service Level Agreement SLA
    • Public DNS Service Level Agreement SLA
  • Typical Practices
    • Implement URL Forwarding via Nginx
    • Local IDC Interconnection with Cloud DNS Service via Resolver
    • Quickly Set Up Private Domain Name Resolution Service Using Terraform
  • Document center
  • arrow
  • DNS
  • arrow
  • SDK
  • arrow
  • Golang-SDK
  • arrow
  • Exception handling
Table of contents on this page
  • Client exception
  • Server exception
  • SDK logging
  • Default logging
  • Project usage

Exception handling

Updated at:2025-11-11

Exception handling

The Go language uses the error type to identify errors. LD supports two types of errors, as shown in the table below:

Error type Description
BceClientError Errors caused by user operations
BceServiceError Errors returned by the LD service

When users invoke LD-related APIs through the SDK, the required results will be returned along with any errors that occur. Users can retrieve and handle these errors. An example is provided below:

Plain Text
1args := &ListPrivateZoneRequest{
2    Marker: "zone-mk2guy4qxd7c",
3}
4result, err := LdClient.ListPrivateZone(args)
5if err != nil {
6	switch realErr := err.(type) {
7	case *bce.BceClientError:
8		fmt.Println("client occurs error:", realErr.Error())
9	case *bce.BceServiceError:
10		fmt.Println("service occurs error:", realErr.Error())
11	default:
12		fmt.Println("unknown error:", err)
13	}
14}

Client exception

A client exception occurs when the client encounters issues while sending requests or transmitting data to LD. For instance, if the network connection is unavailable during a request, a BceClientError will be returned.

Server exception

A server exception is generated when LD server-side errors occur. The service returns detailed error messages to assist in troubleshooting. For common server exceptions, refer to LD Error Code

SDK logging

The LD GO SDK has a logging module that supports six levels, three output destinations (standard output, standard error, file), and basic format settings. Its import path is github.com/baidubce/bce-sdk-go/util/log. When outputting to a file, it supports setting five log rolling modes (no rolling, rolling by day, rolling by hour, rolling by minute, rolling by size). In this case, the directory for output log files also needs to be set.

Default logging

The LD GO SDK itself uses a package-level global log object, which does not record logs by default. If they need to output SDK-related logs, users must specify the output method and level. See the following examples for details:

Plain Text
1// import "github.com/baidubce/bce-sdk-go/util/log"
2 // Specify output to standard error, output INFO and above levels
3log.SetLogHandler(log.STDERR)
4log.SetLogLevel(log.INFO)
5 // Specify output to standard error and file, DEBUG and above levels, rolling by 1 GB file size
6log.SetLogHandler(log.STDERR | log.FILE)
7log.SetLogDir("/tmp/gosdk-log")
8log.SetRotateType(log.ROTATE_SIZE)
9log.SetRotateSize(1 << 30)
10 // Output to standard output, only output level and log message
11log.SetLogHandler(log.STDOUT)
12log.SetLogFormat([]string{log.FMT_LEVEL, log.FMT_MSG})

Description:

  1. The default log output level is DEBUG
  2. If set to output to a file, the default log output directory is /tmp, and it rolls by hour by default
  3. If set to output to a file and roll by size, the default rolling size is 1 GB
  4. The default log output format is: FMT_LEVEL, FMT_LTIME, FMT_LOCATION, FMT_MSG

Project usage

This logging module has no external dependencies. When users develop projects using the GO SDK, they can directly reference this logging module for use in their projects. Users can continue to use the package-level log object used by the GO SDK or create new log objects. See the following examples for details:

Plain Text
1// Directly use the package-level global log object (will be output together with the GO SDK’s own logs)
2log.SetLogHandler(log.STDERR)
3log.Debugf("%s", "logging message using the log package in the LD go sdk")
4 // Create a new log object (output logs according to custom settings, separated from the GO SDK’s log output)
5myLogger := log.NewLogger()
6myLogger.SetLogHandler(log.FILE)
7myLogger.SetLogDir("/home/log")
8myLogger.SetRotateType(log.ROTATE_SIZE)
9myLogger.Info("this is my own logger from the LD go sdk")

Previous
Quick Start
Next
Initialization