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

Adding a Gateway Response

Updated on 2024-04-03 GMT+08:00

Scenario

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 gateway responses with custom status codes and content, on the API Groups page. 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:
  • The default gateway responses provided by APIG can be edited.
  • You can create gateway responses and configure different responses for APIs in the same API group.
  • 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 APIG Context Variables.

Prerequisites

You have created an API group.

Procedure

  1. Access the shared gateway console.
  2. In the navigation pane, choose API Publishing > API Groups.
  3. Locate the API group for which you want to create or modify a gateway response, and click the group name to go to the API group details page.
  4. Click the Gateway Responses tab and create a gateway response.

    NOTE:
    • To edit a response, click the Edit button in the upper right corner and modify the status code and content of the response.
    • You can modify only the status code and content of a default or custom gateway response, and you cannot change the response type.
    • Error information and other response details can be obtained using variables. For details about the supported variables, see Table 2.

Response Types

Table 1 lists the response types supported by APIG. You can define status codes of responses 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.

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 App

401

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

APIG Context Variables

Table 2 Variables that can be used in response message body

Variable

Description

$context.apiId

API ID.

$context.appId

ID of the app 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.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.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback