Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 1.76 KB

File metadata and controls

58 lines (45 loc) · 1.76 KB

← Retries | Error Handling (中文) | Debugging →


Exception Handling

When a request fails, the SDK throws an instance of HttpRequestError containing rich debugging information.

Exception Types

name Meaning Available Fields
ApiException Server error response (parameter error, resource not found, etc.) status, data
NetworkError Network-level error (DNS failure, connection timeout, etc.) message, originalError
Exception Other unclassified exceptions message

Code Example

import { HttpRequestError } from "@volcengine/sdk-core";

try {
  await client.send(command);
} catch (error) {
  if (error instanceof HttpRequestError) {
    if (error.status !== undefined) {
      if (error.status === 0) {
        console.error("SSL Error");
      } else {
        if (error.data?.ResponseMetadata?.Error) {
          const { Code, Message } = error.data.ResponseMetadata.Error;
          const { RequestId } = error.data.ResponseMetadata;
          console.error(`API Error [${Code}]: ${Message}, RequestId: ${RequestId}`);
        }
      }
    } else if (error.name === "NetworkError") {
      console.error(`Network Error: ${error.message}`);
      if (error.originalError && (error.originalError as any).code) {
        console.error(`Code: ${(error.originalError as any).code}`);
      }
    } else {
      console.error("SDK Exception");
    }
  }
}

Resource Cleanup

The client may hold resources such as network connections. Call destroy before the application exits.

client.destroy();

← Retries | Error Handling (中文) | Debugging →