1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('./Exception');
|
7 |
|
8 | module.exports = class HttpException extends Base {
|
9 |
|
10 | constructor (status, err, data) {
|
11 | super(err, data);
|
12 | this.status = status;
|
13 | }
|
14 |
|
15 | isServerError () {
|
16 | return this.status >= 500;
|
17 | }
|
18 |
|
19 | toString () {
|
20 | const message = this.message || '';
|
21 | const data = this.data === undefined ? '' : util.inspect(this.data);
|
22 | return this.method
|
23 | ? `${this.status} ${this.method} ${this.originalUrl} ${this.ip} ${message} ${data}`
|
24 | : `${this.status} ${message} ${data}`;
|
25 | }
|
26 |
|
27 | setParams (req) {
|
28 | this.method = req.method;
|
29 | this.originalUrl = req.originalUrl;
|
30 | this.ip = req.ip;
|
31 | }
|
32 | };
|
33 |
|
34 | const util = require('util'); |
\ | No newline at end of file |