# Error message is wrapped with success response(200OK)

**URL:** <https://forum.serverless.com/t/error-message-is-wrapped-with-success-response-200ok/9437>\
**Category:** Serverless Framework\
**Tags:** api-gateway\
**Created:** [September 25, 2019, 10:22am UTC](https://forum.serverless.com/t/error-message-is-wrapped-with-success-response-200ok/9437 "2019-09-25T10:22:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![riyaz](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@riyaz](https://forum.serverless.com/u/riyaz)\
**Post date:** [September 25, 2019, 10:22am UTC](https://forum.serverless.com/t/error-message-is-wrapped-with-success-response-200ok/9437/1 "2019-09-25T10:22:13Z")

</div>

```auto
I am using lambda integration. Returning the success response works fine. Returning error is received as success in client.
I tried using `callback(new Error('[404] Not found'));` , `callback(null, { statusCode: 404, body: 'Not found', headers: { 'Content-Type': 'text/plain' } });` , tried with custom status code too but no luck. 

Here is sample yml for helloworld function:

helloworld:
  handler: helloWorld/handler.hello
  timeout: 15
  events:
    - http:
        path: hello/worlds
        method: get
        integration: lambda
        request:
            template:
              application/json: "${file(helloWorld/test.vtl)}"
        response:
            headers:
              Access-Control-Allow-Origin: "'*'"
              Content-Type: "'application/json'"
            template: $input.path('$.errorMessage')
        cors:
            origin: '*'
            headers:
              - Content-Type
              - X-Amz-Date
              - Authorization
              - X-Api-Key
              - X-Amz-Security-Token
              - X-Amz-User-Agent
              - Startlower
              - Text
              - Access-Control-Allow-Headers
              - Access-Control-Allow-Origin
            allowCredentials: false
        authorizer:
            name: ftAuth
            type: request
  package:
    include: # Specify the directories and files which should be included in the deployment package for this specific function.
      - helloWorld/**

```

---

<div class="post-metadata">

**Author:** ![majindageta](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/majindageta/32/3200_2.png) [@majindageta](https://forum.serverless.com/u/majindageta)\
**Post date:** [September 25, 2019, 2:23pm UTC](https://forum.serverless.com/t/error-message-is-wrapped-with-success-response-200ok/9437/2 "2019-09-25T14:23:25Z")

</div>

I almost always use the proxy integration so I’m not fully prepared for this.  
Before using serverless I fallowed this guide:

> **[Error handling in AWS API Gateway with Lambda](https://medium.com/@pahud/error-handling-in-aws-api-gateway-with-lambda-28fb86b3ea1e)**
>
> When it comes to error handling in AWS API Gateway with Lambda, you may find this blog very informative. After some hours of experiments I…

Hope it helps
