El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating a Gateway Response

Updated on 2024-08-07 GMT+08:00

A gateway response is displayed if APIG fails to process an API request. APIG provides a set of default responses and also allows you to create responses with custom status codes and content. The response content must be in JSON format.

For example, the content of a default gateway response is as follows:

{"error_code": "$context.error.code", "error_msg": "$context.error.message", "request_id": "$context.requestId"}

You can add a response with the following content:

{"errorcode": "$context.error.code", "errormsg": "$context.error.message", "requestid": "$context.requestId","apiId":"$context.apiId"}

You can add more fields to or delete existing fields from the JSON body.

NOTE:
  • You can create a maximum of four gateway responses for each group.
  • A maximum of 10 response headers can be customized. The key of a response header can contain 1 to 128 characters, including digits, letters, and underscores (_). The value can reference runtime variables (see Context Variables), but cannot contain double brackets ([[ or ]]).
  • The type of a default or custom response cannot be modified, but the status code and content of the response can.
  • The type of a gateway response cannot be changed. For details, see Response Types.
  • Gateway responses can contain the API gateway context variables (starting with $context). For details, see Context Variables.

Procedure

  1. Go to the APIG console.
  1. Select a dedicated gateway at the top of the navigation pane.
  1. Choose API Management > API Groups.
  1. Click a group name.
  2. Click the Group Information tab.
  3. In the Gateway Responses area, create or modify gateway responses.

    To cancel modifications to a default response, click Restore Defaults in the upper right.

Response Types

The following table lists the response types supported by APIG. You can define status codes to meet your service requirements.

Table 1 Error response types supported by APIG

Response Name

Default Status Code

Description

Access Denied

403

Access denied. For example, the access control policy is triggered or an attack is detected.

Authorizer Configuration Error

500

A custom authorizer error has occurred. For example, communication failed or an error response was returned.

Authorizer Failed

500

The custom authorization failed.

Incorrect Identity Source

401

The identity source of the custom authorizer is missing or invalid.

Third-Party Configuration Error

500

A third-party authorizer error has occurred. For example, communication failed or an error response was returned.

Third-Party Authorizer Failure

401

The third-party authorizer returns an authentication failure.

Incorrect Third-Party Identity Source

401

The identity source of the third-party authorizer is missing.

Authentication Failure

401

IAM or app authentication failed.

Identity Source Not Found

401

No identity source has been specified.

Backend Timeout

504

Communication with the backend service timed out.

Backend Unavailable

502

The backend service is unavailable due to communication error.

Default 4XX

-

Another 4XX error occurred.

Default 5XX

-

Another 5XX error occurred.

No API Found

404

No API is found.

Incorrect Request Parameters

400

The request parameters are incorrect or the HTTP method is not supported.

Request Throttled

429

The request was rejected due to request throttling.

Unauthorized Credential

401

The credential you are using has not been authorized to call the API.

Context Variables

Table 2 Variables that can be used in response message body

Variable

Description

$context.apiId

API ID.

$context.apiName

API name.

$context.appId

ID of the credential that calls the API.

$context.appName

Name of the credential that calls the API.

$context.requestId

Request ID generated when the API is called.

$context.stage

Deployment environment in which the API is called.

$context.sourceIp

Source IP address of the API caller.

$context.reqPath

API request path, excluding the query string.

$context.reqUri

API request path, including the query string.

$context.reqMethod

Request method.

$context.authorizer.frontend.property

Values of the specified attribute–value pairs mapped to the context in the frontend custom authorizer response

$context.authorizer.backend.property

Values of the specified attribute–value pairs mapped to the context in the backend custom authorizer response

$context.error.message

Error message.

$context.error.code

Error code.

$context.error.type

Error type.

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback