In my project, I am using serverless. I am trying to change the default statusCodes and response. I have tried the following.
dashboard:
handler: src/common/dashboard.dashboard
role: CommonServicesFullAccessRole
timeout: 30
events:
- http:
integration: lambda
path: ui/dashboard/
method: get
request:
parameters:
paths:
id: true
response:
headers:
Content-Type: "'text/html'"
template: $input.path('$')
statusCodes:
400:
pattern: '[\s\S]*Bad Request[\s\S]*'
template: $input.path('$.errorMessage')
headers:
Content-Type: "'text/plain'"
In my lambda, I am returning the error callback as
return callback('Bad Request');
Still, I am not able to get the response with the specified statusCode. I am not sure where the exact error is. Following is the response I am getting.
Please help me solve this. Thank you...
Try the below.
Though I am not
Node
user, I have seen those example codes usingError
object inNode
.For
Python
, I test it if working with yourserverless
config on theresponse
block.--Edit--
I don't think my
serverless.yml
has a difference against yours since I just copied the part of yours.However, I attach my test code, hoping that it would help you.
# serverless.yml
# handler.js
# curl