@@ -19,7 +19,7 @@ export class ErrorHandler implements ErrorHandlerContract {
19
19
/**
20
20
* Stores the list of report callbacks.
21
21
*/
22
- protected readonly reportCallbacks : Array < ( ctx : HttpContext , error : HttpError ) => void | Promise < void > >
22
+ protected readonly reportCallbacks : Array < ( error : HttpError , ctx : HttpContext ) => void | Promise < void > >
23
23
24
24
/**
25
25
* Create a new error handler instance.
@@ -85,7 +85,7 @@ export class ErrorHandler implements ErrorHandlerContract {
85
85
/**
86
86
* Register a reportable callback.
87
87
*/
88
- reportable ( reportUsing : ( ctx : HttpContext , error : any ) => void | Promise < void > ) : ErrorHandler {
88
+ reportable ( reportUsing : ( error : any , ctx : HttpContext ) => void | Promise < void > ) : ErrorHandler {
89
89
return tap ( this , ( ) => {
90
90
this . reportCallbacks . push ( reportUsing )
91
91
} )
@@ -112,25 +112,25 @@ export class ErrorHandler implements ErrorHandlerContract {
112
112
/**
113
113
* Handle the given error.
114
114
*/
115
- async handle ( ctx : HttpContext , error : any ) : Promise < void > {
116
- await this . report ( ctx , error )
117
- await this . render ( ctx , error )
115
+ async handle ( error : any , ctx : HttpContext ) : Promise < void > {
116
+ await this . report ( error , ctx )
117
+ await this . render ( error , ctx )
118
118
}
119
119
120
120
/**
121
121
* Report an error.
122
122
*/
123
- async report ( ctx : HttpContext , error : any ) : Promise < void > {
123
+ async report ( error : any , ctx : HttpContext ) : Promise < void > {
124
124
if ( this . shouldNotReport ( error ) ) {
125
125
return
126
126
}
127
127
128
- if ( await this . errorReported ( ctx , error ) ) {
128
+ if ( await this . errorReported ( error , ctx ) ) {
129
129
return
130
130
}
131
131
132
132
const handled = await Collect ( this . reportCallbacks ) . any ( async reportCallback => {
133
- return await reportCallback ( ctx , error )
133
+ return await reportCallback ( error , ctx )
134
134
} )
135
135
136
136
if ( handled ) {
@@ -147,54 +147,54 @@ export class ErrorHandler implements ErrorHandlerContract {
147
147
}
148
148
149
149
/**
150
- * Determine whether the given `error` is implementing a `handle ` method and
151
- * that `handle ` method returns a truthy value, like a valid HTTP response.
150
+ * Determine whether the given `error` is implementing a `report ` method and
151
+ * that `report ` method returns a truthy value, like a valid HTTP response.
152
152
*/
153
- async errorReported ( ctx : HttpContext , error : any ) : Promise < unknown > {
153
+ async errorReported ( error : any , ctx : HttpContext ) : Promise < unknown > {
154
154
if ( typeof error . report !== 'function' ) {
155
155
return false
156
156
}
157
157
158
- return await error . report ( error , ctx )
158
+ return ! ! ( await error . report ( error , ctx ) )
159
159
}
160
160
161
161
/**
162
162
* Render the error into an HTTP response.
163
163
*/
164
- async render ( ctx : HttpContext , error : any ) : Promise < any > {
165
- if ( await this . errorRendered ( ctx , error ) ) {
164
+ async render ( error : any , ctx : HttpContext ) : Promise < any > {
165
+ if ( await this . errorRendered ( error , ctx ) ) {
166
166
return
167
167
}
168
168
169
169
const httpError = HttpError . wrap ( error )
170
170
171
171
if ( ctx . request . wantsJson ( ) ) {
172
- return this . renderJsonResponse ( ctx , httpError )
172
+ return this . renderJsonResponse ( httpError , ctx )
173
173
}
174
174
175
175
if ( this . app . env ( ) . isProduction ( ) ) {
176
- return this . renderJsonResponse ( ctx , httpError )
176
+ return this . renderJsonResponse ( httpError , ctx )
177
177
}
178
178
179
- return await this . renderViewResponse ( ctx , httpError )
179
+ return await this . renderViewResponse ( httpError , ctx )
180
180
}
181
181
182
182
/**
183
183
* Determine whether the given `error` is implementing a `render` method and
184
184
* that `render` method returns a truthy value, like a valid HTTP response.
185
185
*/
186
- async errorRendered ( ctx : HttpContext , error : any ) : Promise < unknown > {
186
+ async errorRendered ( error : any , ctx : HttpContext ) : Promise < unknown > {
187
187
if ( typeof error . render !== 'function' ) {
188
188
return false
189
189
}
190
190
191
- return await error . render ( ctx , error )
191
+ return await error . render ( error , ctx )
192
192
}
193
193
194
194
/**
195
195
* Creates a JSON response depending on the app’s environment.
196
196
*/
197
- protected renderJsonResponse ( ctx : HttpContext , error : HttpError ) : void {
197
+ protected renderJsonResponse ( error : HttpError , ctx : HttpContext ) : void {
198
198
const { message, stack, status : statusCode } = error
199
199
200
200
this . app . env ( ) . isProduction ( )
@@ -205,7 +205,7 @@ export class ErrorHandler implements ErrorHandlerContract {
205
205
/**
206
206
* Creates an HTML response depending on the app’s environment.
207
207
*/
208
- protected async renderViewResponse ( ctx : HttpContext , error : HttpError ) : Promise < void > {
208
+ protected async renderViewResponse ( error : HttpError , ctx : HttpContext ) : Promise < void > {
209
209
if ( await this . isMissingTemplateFor ( error ) ) {
210
210
return await this . renderYouchResponse ( ctx , error )
211
211
}
0 commit comments