Skip to content

Commit

Permalink
make error render and error report methods required
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Dec 11, 2023
1 parent 66722c2 commit 0cba632
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"@supercharge/map": "~1.5.0",
"@supercharge/strings": "~2.0.0",
"globby": "~14.0.0",
"normalize-path": "~3.0.0"
"normalize-path": "~3.0.0",
"type-fest": "~4.8.3"
},
"devDependencies": {
"@types/normalize-path": "~3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/core/renderable-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export interface RenderableError extends Error {
/**
* Render an error into an HTTP response.
*/
render?(error: Error, ctx: HttpContext): Promise<any>
render(error: Error, ctx: HttpContext): Promise<any> | any
}
2 changes: 1 addition & 1 deletion packages/contracts/src/core/reportable-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface ReportableError extends Error {
/**
* Report an error, to a 3rd-party service, the console, a file, or somewhere else.
*/
report?(error: Error, ctx: HttpContext): Promise<any> | any
report(error: Error, ctx: HttpContext): Promise<any> | any
}
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@supercharge/set": "~2.2.1",
"@supercharge/support": "^4.0.0-alpha.1",
"dotenv": "~16.3.1",
"type-fest": "~4.8.3",
"youch": "~3.3.3",
"youch-terminal": "~2.2.3"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/errors/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import Youch from 'youch'
import { SetOptional } from 'type-fest'
import { tap } from '@supercharge/goodies'
import { HttpError } from './http-error.js'
import { Collect } from '@supercharge/collections'
Expand Down Expand Up @@ -150,7 +151,7 @@ export class ErrorHandler implements ErrorHandlerContract {
* Determine whether the given `error` is implementing a `report` method and
* that `report` method returns a truthy value, like a valid HTTP response.
*/
async errorReported (error: ReportableError, ctx: HttpContext): Promise<unknown> {
async errorReported (error: SetOptional<ReportableError, 'report'>, ctx: HttpContext): Promise<unknown> {
if (typeof error.report !== 'function') {
return false
}
Expand Down Expand Up @@ -183,7 +184,7 @@ export class ErrorHandler implements ErrorHandlerContract {
* Determine whether the given `error` is implementing a `render` method and
* that `render` method returns a truthy value, like a valid HTTP response.
*/
async errorRendered (error: RenderableError, ctx: HttpContext): Promise<unknown> {
async errorRendered (error: SetOptional<RenderableError, 'render'>, ctx: HttpContext): Promise<unknown> {
if (typeof error.render !== 'function') {
return false
}
Expand Down

0 comments on commit 0cba632

Please sign in to comment.