{
  "id": 2677498,
  "title": "Web APIs and Batch Jobs Communicate Failure Differently",
  "url": "https://urgent.news/2026/08/22/web-apis-and-batch-jobs-communicate-failure-differently",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-22T23:58:22.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/tohru_yaginuma_4f041533c6/web-apis-and-batch-jobs-communicate-failure-differently-2mga"
  },
  "original_language": "en",
  "account": "Web APIs and batch jobs handle failure in distinct ways. Web APIs convey success or failure to clients via HTTP status codes, such as an HTTP 500 Internal Server Error. However, batch jobs require a different approach.\n\nTraditionally, batch jobs might return false or { status: 500 } to signal an error. Yet, Lambda functions, a common platform for batch jobs, do not consider these return values as failures. Consequently, even if the application coded a failure, the execution environment might still register it as successful. As a result, the invocation won't be logged in CloudWatch's Errors metric, and monitoring systems like alarms won't trigger.\n\nThis realization came when attempting to send Slack notifications for failing batch jobs. Initially, the thought was straightforward: monitor Lambda execution errors with CloudWatch and use AWS notification services to alert via Slack. But upon examining the existing batch code, it became clear that the error handling was inadequate. It only signaled the code level, not the execution environment.\n\nTo resolve this, the error handling was refactored to throw an exception when an error occurred: throw new Error(...). This action caused the Lambda invocation itself to fail, which was then recognized by CloudWatch's Errors metric. Only then could monitoring and alerting systems observe the failure, leading to an appropriate Slack notification.\n\nThis experience underscored the importance of considering error handling not just within the application but also in ensuring that failures are observable by the execution environment and monitoring systems. While Web APIs use HTTP status codes for communication, batch jobs necessitate a failure state that the execution environment can detect. Proper error handling for batch jobs involves both application-level corrections and ensuring the environment and monitoring systems can identify and respond to failures.",
  "summary": "Long Story Short Web APIs can communicate failure through HTTP status codes, but batch jobs need to terminate in a way that allows the execution environment to recognize that the process has failed. In this case, I changed the error handling to throw an exception. This caused failed Lambda invocations to be reflected in the CloudWatch Errors metric, which allowed the alarm to trigger. Error…",
  "key_points": [
    "Web APIs communicate failure via HTTP status codes like HTTP 500.",
    "Batch jobs need a different failure handling approach than HTTP codes.",
    "Lambda functions don't treat return values like false or { status: 500 } as failures."
  ],
  "editors_take": "Inconsistent error handling between Web APIs and batch jobs can lead to undetected failures, highlighting the need for a distinct approach to signal and log errors in batch job executions.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}