I'm working on a project with this workflow : an API Gateway (defined using open api) trigger a Step function from AWS. There is 2 steps, and in case of errors, there is a catch block in the State machine definition.
But I'm facing an issue with error handling. Even if my code throw an error (400 for example), my Postman (or other REST API testing tools) respond with a 200. And I would like to have a 500/400...
Here is the code :
Step function definiton as serverless
stepFunctions:
stateMachines:
PostPayment:
name: testfunction
type: EXPRESS
definition:
Comment: 'test'
StartAt: Function1
States:
Function1:
Type: Task
Resource: !GetAtt Function1.Arn
Catch:
- ErrorEquals: ['HandledError']
Next: Fallback
Next: Function2
Function2:
Type: Task
Resource: !GetAtt Function2.Arn
Catch:
- ErrorEquals: ['HandledError']
Next: Fallback
End: true
Fallback:
Type: Fail
Cause: "Error occured",
Error: "Error"
and here is my openapi yml
x-amazon-apigateway-request-validator: all
x-amazon-apigateway-integration:
requestParameters:
integration.request.path.id: method.request.path.id
requestTemplates:
application/json:
Fn::Sub: |-
{
"input": "{\"id\": \"$input.params().path.get('id')\"}",
"stateMachineArn": "<ARN>"
}
httpMethod: POST
type: aws
credentials: !GetAtt ApiGatewayExecutionRole.Arn
uri: !GetAtt StartSyncExecution.Arn
responses:
"200":
statusCode: 200
responseTemplates:
application/json: $util.parseJson($util.parseJson($input.body).output).body
"401":
statusCode: 401
responseTemplates:
application/json: $util.parseJson($util.parseJson($input.body).cause).errorMessage
"400":
statusCode: 400
responseTemplates:
application/json: $util.parseJson($util.parseJson($input.body).cause).errorMessage
"404":
statusCode: 404
responseTemplates:
application/json: $util.parseJson($util.parseJson($input.body).cause).errorMessage
"500":
statusCode: 500
responseTemplates:
application/json: $util.parseJson($util.parseJson($input.body).cause).errorMessage
With this configuration I always pass in 200 statusCode case. But I have an error as body response since my code is throwing an error.
Did I miss something?