Skip to content

Commit e4b8319

Browse files
committed
fix: http exception let the global exception handler handle it
Fixes #22
1 parent bb72d4e commit e4b8319

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

npm-audit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h5 class="card-title">
5555
<div class="card">
5656
<div class="card-body">
5757
<h5 class="card-title">
58-
August 27th 2020, 3:46:36 pm
58+
August 27th 2020, 3:51:23 pm
5959
</h5>
6060
<p class="card-text">Last updated</p>
6161
</div>

src/Exceptions/HttpException.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
/// <reference path="../../adonis-typings/index.ts" />
1111

1212
import { Exception, interpolate } from '@poppinss/utils'
13-
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
1413

1514
import { E_HTTP_EXCEPTION } from '../../exceptions.json'
1615

@@ -37,12 +36,4 @@ export class HttpException extends Exception {
3736
error.body = error.message
3837
return error
3938
}
40-
41-
/**
42-
* Handle itself by making the response. This only works when using the
43-
* base exception handler shipped by AdonisJs
44-
*/
45-
public handle(error: HttpException, ctx: HttpContextContract) {
46-
ctx.response.status(error.status).send(error.body)
47-
}
4839
}

src/Response/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ import { CookieSerializer } from '../Cookie/Serializer'
4141
import { HttpException } from '../Exceptions/HttpException'
4242
import { E_CANNOT_SERIALIZE_RESPONSE_BODY } from '../../exceptions.json'
4343

44+
class AbortException extends HttpException {
45+
/**
46+
* Handle itself by making the response. This only works when using the
47+
* base exception handler shipped by AdonisJs
48+
*/
49+
public handle(error: HttpException, ctx: HttpContextContract) {
50+
ctx.response.status(error.status).send(error.body)
51+
}
52+
}
53+
4454
/**
4555
* The response is a wrapper over [ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse)
4656
* streamlining the process of writing response body and automatically setting up appropriate headers.
@@ -809,7 +819,7 @@ export class Response extends Macroable implements ResponseContract {
809819
* used when status is not defined
810820
*/
811821
public abort(body: any, status?: number): never {
812-
throw HttpException.invoke(body, status || 400)
822+
throw AbortException.invoke(body, status || 400)
813823
}
814824

815825
/**

0 commit comments

Comments
 (0)