domainErrorHttpStatus
Call Signature
Section titled “Call Signature”domainErrorHttpStatus(
error):DomainErrorHttpStatus
Defined in: packages/ddd-core/http/domain-error-http-status.ts:48
Maps this package’s errors to an HTTP status, for any HTTP framework.
| Exception | Status | Message |
|---|---|---|
| ConcurrencyConflictError | 409 Conflict | the exception’s |
| EntityNotFoundException | 404 Not Found | the exception’s |
| MissingTenantContextError | 500 Internal Server Error | 'Internal server error' |
| any other DomainException | 400 Bad Request | the exception’s |
A missing tenant is a server misconfiguration, not a caller mistake, so it answers 500 and keeps its message, which names the failed operation, out of the response.
An application maps its own DomainException subclasses first and passes the
rest here. Anything that is not a DomainException returns undefined, so
the framework’s default handling still applies.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Example
Section titled “Example”An Express error handler
app.use((err, req, res, next) => { const mapped = domainErrorHttpStatus(err); if (!mapped) return next(err); res.status(mapped.statusCode).json(mapped);});Call Signature
Section titled “Call Signature”domainErrorHttpStatus(
error):DomainErrorHttpStatus|undefined
Defined in: packages/ddd-core/http/domain-error-http-status.ts:51
Maps this package’s errors to an HTTP status, for any HTTP framework.
| Exception | Status | Message |
|---|---|---|
| ConcurrencyConflictError | 409 Conflict | the exception’s |
| EntityNotFoundException | 404 Not Found | the exception’s |
| MissingTenantContextError | 500 Internal Server Error | 'Internal server error' |
| any other DomainException | 400 Bad Request | the exception’s |
A missing tenant is a server misconfiguration, not a caller mistake, so it answers 500 and keeps its message, which names the failed operation, out of the response.
An application maps its own DomainException subclasses first and passes the
rest here. Anything that is not a DomainException returns undefined, so
the framework’s default handling still applies.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”DomainErrorHttpStatus | undefined
Example
Section titled “Example”An Express error handler
app.use((err, req, res, next) => { const mapped = domainErrorHttpStatus(err); if (!mapped) return next(err); res.status(mapped.statusCode).json(mapped);});