Skip to content

Allow fallible HTTP handlers and map uncaught errors to 500 responses #18

Description

@yorkin-bot

Summary

HTTP handlers and middleware are currently required to be noraise:

This prevents ordinary fallible operations—JSON decoding, filesystem access, database calls, SSR, upstream HTTP calls—from propagating to a central error boundary.

Reproduction

This natural handler does not type-check:

app.post("/json", event => {
  let payload : Json = event.req.json()
  payload
})

moon check --target native reports:

Error [4122]: Function with error can only be used inside a function
with error types in its signature.

Applications must therefore catch every error inside every handler, discard it, or use an aborting construct such as try!. None of those choices allows consistent logging and conversion to an HTTP 500 response.

Expected behavior

Handlers and middleware should be allowed to raise checked errors. Mocket should catch unhandled request errors at one well-defined boundary and:

  • return a default 500 response without terminating the process;
  • offer an error hook/middleware for logging and custom responses;
  • preserve cancellation rather than treating it as an ordinary request failure;
  • keep successfully handled errors local when the application chooses to catch them.

Existing noraise handlers should remain valid inputs to the more general handler type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions