doc-exports/docs/fg/umn/functiongraph_03_0290.html
Chen, Junjie dac566cf2f FG UMN 20230725 version
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>
2024-04-03 10:30:56 +00:00

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 = "&lt;html&gt;&lt;title&gt;FunctionStage&lt;/title&gt;"
+ "&lt;h1&gt;This is a simple APIG trigger test&lt;/h1&gt;&lt;br&gt;"
+ "&lt;h2&gt;This is a simple APIG trigger test&lt;/h2&gt;&lt;br&gt;"
+ "&lt;h3&gt;This is a simple APIG trigger test&lt;/h3&gt;"
+ "&lt;/html&gt;";
int code = 200;
boolean isBase64 = false;
Map&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
headers.put("Content-Type", "text/html; charset=utf-8");
return new HttpTriggerResponse(body, headers, code, isBase64);
}
class HttpTriggerResponse {
private String body;
private Map&lt;String, String&gt; headers;
private int statusCode;
private boolean isBase64Encoded;
public HttpTriggerResponse(String body, Map&lt;String,String&gt; 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>