forked from docs/doc-exports
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com> Co-authored-by: Chen, Junjie <chenjunjie@huawei.com> Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
53 lines
2.7 KiB
HTML
53 lines
2.7 KiB
HTML
<a name="functiongraph_03_0290"></a><a name="functiongraph_03_0290"></a>
|
|
|
|
<h1 class="topictitle1">What If Error Code 500 Is Reported When Functions that Use APIG Triggers Return Strings?</h1>
|
|
<div id="body1531290258837"><p id="functiongraph_03_0290__p8060118">Ensure that the function response for an invocation by API Gateway has been encapsulated and contains <strong id="functiongraph_03_0290__b19455174514110">body(String)</strong>, <strong id="functiongraph_03_0290__b1667914475113">statusCode(int)</strong>, <strong id="functiongraph_03_0290__b4406125115112">headers(Map)</strong>, and <strong id="functiongraph_03_0290__b164031155181119">isBase64Encoded(boolean)</strong>.</p>
|
|
<p id="functiongraph_03_0290__p1090084184519">The following is an example response returned by a Node.js function that uses an APIG trigger:</p>
|
|
<pre class="codeblock" id="functiongraph_03_0290__codeblock10483720468">exports.handler = function (event, context, callback) {
|
|
const response = {
|
|
'statusCode': 200,
|
|
'isBase64Encoded': false,
|
|
'headers': {
|
|
"Content-type": "application/json"
|
|
},
|
|
'body': 'Hello, FunctionGraph with APIG',
|
|
}
|
|
callback(null, response);
|
|
}</pre>
|
|
<p id="functiongraph_03_0290__p15606846124613">The following is an example response returned by a Java function that uses an APIG trigger:</p>
|
|
<pre class="codeblock" id="functiongraph_03_0290__codeblock1956123218486">import java.util.Map;
|
|
|
|
public HttpTriggerResponse index(String event, Context context){
|
|
String body = "<html><title>FunctionStage</title>"
|
|
+ "<h1>This is a simple APIG trigger test</h1><br>"
|
|
+ "<h2>This is a simple APIG trigger test</h2><br>"
|
|
+ "<h3>This is a simple APIG trigger test</h3>"
|
|
+ "</html>";
|
|
int code = 200;
|
|
boolean isBase64 = false;
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
headers.put("Content-Type", "text/html; charset=utf-8");
|
|
return new HttpTriggerResponse(body, headers, code, isBase64);
|
|
}
|
|
|
|
|
|
class HttpTriggerResponse {
|
|
private String body;
|
|
private Map<String, String> headers;
|
|
private int statusCode;
|
|
private boolean isBase64Encoded;
|
|
public HttpTriggerResponse(String body, Map<String,String> headers, int statusCode, boolean isBase64Encoded){
|
|
this.body = body;
|
|
this.headers = headers;
|
|
this.statusCode = statusCode;
|
|
this.isBase64Encoded = isBase64Encoded;
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_03_0100.html">Trigger Management FAQs</a></div>
|
|
</div>
|
|
</div>
|
|
|