@@ -12,14 +12,14 @@ import { Exception } from '@poppinss/utils'
1212import { LoggerFactory } from '@adonisjs/logger/factories'
1313
1414import { errors , HttpContext } from '../../index.js'
15+ import { ExceptionHandler } from '../../src/exception_handler.js'
1516import { HttpContextFactory } from '../../factories/http_context.js'
16- import { HttpExceptionHandler } from '../../src/exception_handler.js'
1717import { StatusPageRange , StatusPageRenderer } from '../../src/types/server.js'
1818
1919test . group ( 'Exception handler | handle' , ( ) => {
2020 test ( 'handle error by pretty printing it using youch' , async ( { assert } ) => {
2121 const logger = new LoggerFactory ( ) . create ( )
22- const exceptionHandler = new HttpExceptionHandler ( logger )
22+ const exceptionHandler = new ExceptionHandler ( logger )
2323 const ctx = new HttpContextFactory ( ) . create ( )
2424
2525 const error = new Error ( 'Something went wrong' )
@@ -31,7 +31,7 @@ test.group('Exception handler | handle', () => {
3131
3232 test ( 'pretty error as JSON when request accepts JSON' , async ( { assert } ) => {
3333 const logger = new LoggerFactory ( ) . create ( )
34- const exceptionHandler = new HttpExceptionHandler ( logger )
34+ const exceptionHandler = new ExceptionHandler ( logger )
3535 const ctx = new HttpContextFactory ( ) . create ( )
3636
3737 ctx . request . request . headers [ 'accept' ] = 'application/json'
@@ -46,7 +46,7 @@ test.group('Exception handler | handle', () => {
4646
4747 test ( 'pretty error as JSON when request accepts JSONAPI' , async ( { assert } ) => {
4848 const logger = new LoggerFactory ( ) . create ( )
49- const exceptionHandler = new HttpExceptionHandler ( logger )
49+ const exceptionHandler = new ExceptionHandler ( logger )
5050 const ctx = new HttpContextFactory ( ) . create ( )
5151
5252 ctx . request . request . headers [ 'accept' ] = 'application/vnd.api+json'
@@ -60,7 +60,7 @@ test.group('Exception handler | handle', () => {
6060 } )
6161
6262 test ( 'do not render stack trace when debugging is disabled' , async ( { assert } ) => {
63- class AppExceptionHandler extends HttpExceptionHandler {
63+ class AppExceptionHandler extends ExceptionHandler {
6464 protected debug : boolean = false
6565 }
6666
@@ -78,7 +78,7 @@ test.group('Exception handler | handle', () => {
7878 test ( 'do not render stack trace in JSON response when debugging is disabled' , async ( {
7979 assert,
8080 } ) => {
81- class AppExceptionHandler extends HttpExceptionHandler {
81+ class AppExceptionHandler extends ExceptionHandler {
8282 protected debug : boolean = false
8383 }
8484
@@ -97,7 +97,7 @@ test.group('Exception handler | handle', () => {
9797 test ( 'do not render stack trace in JSON API response when debugging is disabled' , async ( {
9898 assert,
9999 } ) => {
100- class AppExceptionHandler extends HttpExceptionHandler {
100+ class AppExceptionHandler extends ExceptionHandler {
101101 protected debug : boolean = false
102102 }
103103
@@ -123,7 +123,7 @@ test.group('Exception handler | handle', () => {
123123
124124 test ( 'use error status code' , async ( { assert } ) => {
125125 const logger = new LoggerFactory ( ) . create ( )
126- const exceptionHandler = new HttpExceptionHandler ( logger )
126+ const exceptionHandler = new ExceptionHandler ( logger )
127127 const ctx = new HttpContextFactory ( ) . create ( )
128128
129129 const error = new Exception ( 'Something went wrong' , { status : 401 } )
@@ -134,7 +134,7 @@ test.group('Exception handler | handle', () => {
134134
135135 test ( 'render error using the error handle method' , async ( { assert } ) => {
136136 const logger = new LoggerFactory ( ) . create ( )
137- const exceptionHandler = new HttpExceptionHandler ( logger )
137+ const exceptionHandler = new ExceptionHandler ( logger )
138138 const ctx = new HttpContextFactory ( ) . create ( )
139139
140140 class MyError extends Exception {
@@ -151,7 +151,7 @@ test.group('Exception handler | handle', () => {
151151 } )
152152
153153 test ( 'render status page' , async ( { assert } ) => {
154- class AppExceptionHandler extends HttpExceptionHandler {
154+ class AppExceptionHandler extends ExceptionHandler {
155155 protected renderStatusPages : boolean = true
156156 protected statusPages : Record < StatusPageRange , StatusPageRenderer > = {
157157 '400..499' : ( error , ctx ) => {
@@ -174,7 +174,7 @@ test.group('Exception handler | handle', () => {
174174 } )
175175
176176 test ( 'do not render status page when exception has handle method' , async ( { assert } ) => {
177- class AppExceptionHandler extends HttpExceptionHandler {
177+ class AppExceptionHandler extends ExceptionHandler {
178178 protected renderStatusPages : boolean = true
179179 protected statusPages : Record < StatusPageRange , StatusPageRenderer > = {
180180 '400..499' : ( error , ctx ) => {
@@ -202,7 +202,7 @@ test.group('Exception handler | handle', () => {
202202
203203 test ( 'handle literal values raised as exception' , async ( { assert } ) => {
204204 const logger = new LoggerFactory ( ) . create ( )
205- const exceptionHandler = new HttpExceptionHandler ( logger )
205+ const exceptionHandler = new ExceptionHandler ( logger )
206206 const ctx = new HttpContextFactory ( ) . create ( )
207207
208208 ctx . request . request . headers [ 'accept' ] = 'application/json'
@@ -219,7 +219,7 @@ test.group('Exception handler | report', () => {
219219 test ( 'report error using logger' , async ( { assert } ) => {
220220 const logs : string [ ] = [ ]
221221 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
222- const exceptionHandler = new HttpExceptionHandler ( logger )
222+ const exceptionHandler = new ExceptionHandler ( logger )
223223 const ctx = new HttpContextFactory ( ) . create ( )
224224
225225 const error = new Error ( 'Something went wrong' )
@@ -239,7 +239,7 @@ test.group('Exception handler | report', () => {
239239 test ( 'report errors with status code in 400 range as a warning' , async ( { assert } ) => {
240240 const logs : string [ ] = [ ]
241241 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
242- const exceptionHandler = new HttpExceptionHandler ( logger )
242+ const exceptionHandler = new ExceptionHandler ( logger )
243243 const ctx = new HttpContextFactory ( ) . create ( )
244244
245245 const error = new Exception ( 'Something went wrong' , { status : 410 } )
@@ -259,7 +259,7 @@ test.group('Exception handler | report', () => {
259259 test ( 'report errors with status code below 400 as info' , async ( { assert } ) => {
260260 const logs : string [ ] = [ ]
261261 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
262- const exceptionHandler = new HttpExceptionHandler ( logger )
262+ const exceptionHandler = new ExceptionHandler ( logger )
263263 const ctx = new HttpContextFactory ( ) . create ( )
264264
265265 const error = new Exception ( 'Something went wrong' , { status : 302 } )
@@ -279,7 +279,7 @@ test.group('Exception handler | report', () => {
279279 test ( 'do not report 400, 422 and 401 error codes' , async ( { assert } ) => {
280280 const logs : string [ ] = [ ]
281281 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
282- const exceptionHandler = new HttpExceptionHandler ( logger )
282+ const exceptionHandler = new ExceptionHandler ( logger )
283283 const ctx = new HttpContextFactory ( ) . create ( )
284284
285285 await exceptionHandler . report ( new Exception ( 'Something went wrong' , { status : 400 } ) , ctx )
@@ -297,7 +297,7 @@ test.group('Exception handler | report', () => {
297297 test ( 'do not report internal exceptions' , async ( { assert } ) => {
298298 const logs : string [ ] = [ ]
299299 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
300- const exceptionHandler = new HttpExceptionHandler ( logger )
300+ const exceptionHandler = new ExceptionHandler ( logger )
301301 const ctx = new HttpContextFactory ( ) . create ( )
302302
303303 await exceptionHandler . report ( new errors . E_CANNOT_LOOKUP_ROUTE ( [ '/' ] ) , ctx )
@@ -314,7 +314,7 @@ test.group('Exception handler | report', () => {
314314 } )
315315
316316 test ( 'do not report when error reporting is turned off' , async ( { assert } ) => {
317- class AppExceptionHandler extends HttpExceptionHandler {
317+ class AppExceptionHandler extends ExceptionHandler {
318318 protected reportErrors : boolean = false
319319 }
320320
@@ -337,7 +337,7 @@ test.group('Exception handler | report', () => {
337337 test ( 'report error using the error report method' , async ( { assert } ) => {
338338 const logs : string [ ] = [ ]
339339 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
340- const exceptionHandler = new HttpExceptionHandler ( logger )
340+ const exceptionHandler = new ExceptionHandler ( logger )
341341 const ctx = new HttpContextFactory ( ) . create ( )
342342
343343 class MyError extends Exception {
@@ -361,7 +361,7 @@ test.group('Exception handler | report', () => {
361361 } )
362362
363363 test ( 'ignore error codes when reporting error' , async ( { assert } ) => {
364- class AppExceptionHandler extends HttpExceptionHandler {
364+ class AppExceptionHandler extends ExceptionHandler {
365365 protected ignoreCodes : string [ ] = [ 'E_CUSTOM_ERROR' ]
366366 }
367367
@@ -388,7 +388,7 @@ test.group('Exception handler | report', () => {
388388 test ( 'log request id in logs when request id exists' , async ( { assert } ) => {
389389 const logs : string [ ] = [ ]
390390 const logger = new LoggerFactory ( ) . pushLogsTo ( logs ) . merge ( { enabled : true } ) . create ( )
391- const exceptionHandler = new HttpExceptionHandler ( logger )
391+ const exceptionHandler = new ExceptionHandler ( logger )
392392 const ctx = new HttpContextFactory ( ) . create ( )
393393
394394 ctx . request . request . headers [ 'x-request-id' ] = '123'
0 commit comments