0

In my lambda I am trying to throw custom error if some logic is incorrect.

I had tried: callback(err), throw new Error(err) It returned the error object, but am not able to update the HTTP response code: enter image description here i.e.: I want to show 500 instead of 200 OK.

Also in my AWS Integration Response, I have declared the response types.

enter image description here

SSS
  • 303
  • 1
  • 2
  • 9
  • Can you post your lambda code? – Jatin Mehrotra Sep 05 '22 at 07:45
  • ` if(!event.client_id || !event.client_secret){ const errorObj = { statusCode: 500, body: "No client_id or client_secret in request" } // context.succeed(errorObj); // callback(errorObj); throw new Error(JSON.stringify(errorObj));}` – SSS Sep 05 '22 at 07:56

1 Answers1

0

This seems to work in Lambda. Adding the statusCode to the response object you return.

exports.handler = async (event) => {
    let response = {
      statusCode: '500',
      body: JSON.stringify({ error: 'error' }),
      headers: {
        'Content-Type': 'application/json',
      }
};
    return response;
};

enter image description here

Costas
  • 109
  • 8