UNPKG

869 BJavaScriptView Raw
1/**
2 * @copyright Copyright (c) 2019 Maxim Khorin <maksimovichu@gmail.com>
3 */
4'use strict';
5
6const Base = require('./Exception');
7
8module.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
34const util = require('util');
\No newline at end of file