# Response Warnings Example

> See how to set warning messages in API responses using g.res.warnings—displaying codes and alerts in your output.

Source: https://docs.apimaker.dev/v1/examples/res/warnings/warnings.html

### Set warnings in the response.

```ts
g.res.warnings = [{ code: 401, message: "This is warning!" }];
return { hello: 'v2' };
```

Response
```json
{
    "success": true,
    "statusCode": 200,
    "data": {
        "hello": "v2"
    },
    "warnings": [
        {
            "code": 401,
            "message": "This is warning!"
        }
    ]
}
```

## Related

- [The global object g](https://docs.apimaker.dev/v1/docs/pre-defined-terms/global-object-g.html) · [Custom APIs](https://docs.apimaker.dev/v1/docs/apis-all/custom-apis/user-created-custom-api.html)
