# Handle error

Marks a failed transfer job as `FAILED` via `ows-project-manager`, recording the failure reason from the Step Functions error. This is the terminal failure step in the product transfer Step Function.

## Event payload

### Input

| Field | Type | Description |
|-------|------|-------------|
| `job_id` | `int` | ID of the transfer job that failed. |
| `error` | `object` | Step Functions error object. Must contain `Cause` or `Error`. |
| `error.Cause` | `str` | (Preferred) Full error cause message, used as the failure reason. |
| `error.Error` | `str` | Error type name, used as the failure reason if `Cause` is absent. |

### Output

```json
{"statusCode": 200}
```

## Setup

This Lambda uses M2M token authentication, which requires AWS access to retrieve credentials at runtime. See [AWS Access](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f) for setup instructions.

Run locally — exposes the Lambda invocation endpoint on port 9000:
```sh
docker compose up dev
```

Invoke the function in a second terminal:
```sh
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" \
  -d '{"job_id": 123, "error": {"Cause": "Something went wrong"}}'
```

## Development

Run linting and tests:
```sh
docker compose run --rm --build unit-lint
```

Format code:
```sh
docker compose run --rm --build format
```

Update the lock file (required after changing `pyproject.toml`):
```sh
docker compose run --rm --build update-lockfile
```
