Tüm Ürünler
Search
Belge Merkezi

Alibaba Cloud SDK:Özel durumları yönetin

Son Güncelleme:Oct 07, 2026

Node.js için Alibaba Cloud SDK V2.0, ağ ve iş mantığı hatalarında belirli hata türleri fırlatır. Özel durum türlerini ve bunların nasıl ele alınacağını öğrenin.

Node.js için Alibaba Cloud SDK V2.0 aşağıdaki özel durum türlerini fırlatır:

  • UnretryableError: Ağ sorunlarından kaynaklanır. Maksimum yeniden deneme sayısına ulaşıldığında fırlatılır. Hata oluştuğunda istek bilgilerini almak için err.data.lastRequest özelliğini kullanın.

  • ResponseError: İş mantığı hatalarından kaynaklanır. Sorun giderme amacıyla aşağıdaki parametreleri kullanın:

    • code: Özel durum için döndürülen hata kodu.

    • message: API çağrısının istek ID'sini de içeren, özel durum için döndürülen hata mesajı.

    • data: Sunucu tarafından döndürülen ayrıntılı hata bilgileri.

Örnek kod:

Önemli

Bu örnekte hata mesajları yalnızca referans amaçlıdır. Üretim ortamında özel durumları asla görmezden gelmeyin. Sistemin sağlamlığını ve kararlılığını sağlamak için uygun özel durum yayılımı, günlük kaydı ve yeniden deneme mekanizmaları kullanın.

const { default: Ecs20140526, DescribeRegionsRequest } = require('@alicloud/ecs20140526');
const { Config } = require('@alicloud/openapi-client');
const { RuntimeOptions } = require('@alicloud/tea-util');
async function main() {
    const config = new Config({
        // Obtain the AccessKey ID of the RAM user from an environment variable.
        accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
        // Obtain the AccessKey secret of the RAM user from an environment variable.
        accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET,
        // The region ID.
        regionId: 'cn-beijing',
    });
    const client = new Ecs20140526(config);
    const request = new DescribeRegionsRequest({
        instanceChargeType: "PrePaid",
    });
    // Create a RuntimeOptions instance and configure runtime parameters. 
    const runtime = new RuntimeOptions();
    try {
        const resp = await client.describeRegionsWithOptions(request, runtime);
        console.log(resp.headers);
        console.log(resp.body);
    } catch (err) {
        // Handle exceptions with caution based on your actual business scenario and do not ignore exceptions in your project. The error message displayed in this example is for reference only. 
        console.log(err.code);
        console.log(err.message);
        console.log(err.data);
    }
}

main();
import Ecs20140526, * as $Ecs20140526 from '@alicloud/ecs20140526';
import * as $OpenApi from '@alicloud/openapi-client';
import * as $Util from '@alicloud/tea-util';

export default class Client {
    static async main(): Promise<void> {
        const config = new $OpenApi.Config({
            // Obtain the AccessKey ID of the RAM user from an environment variable.
            accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
            // Obtain the AccessKey secret of the RAM user from an environment variable.
            accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET,
            // The region that you want to access.
            regionId: 'cn-beijing',
        });
        const client = new Ecs20140526(config);
        const request = new $Ecs20140526.DescribeRegionsRequest({
            instanceChargeType: "PrePaid",
        });
        // Create a RuntimeOptions instance and configure runtime parameters. 
        const runtime = new $Util.RuntimeOptions();
        try {
            const resp = await client.describeRegionsWithOptions(request, runtime);
            console.log(resp.headers);
            console.log(resp.body);
        } catch (err) {
            // Handle exceptions with caution based on your actual business scenario and do not ignore exceptions in your project. The error message displayed in this example is for reference only. 
            console.log(err.code);
            console.log(err.message);
            console.log(err.data);
        }
    }
}