File tree 2 files changed +10
-3
lines changed
2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import StandardError from './standard-error';
11
11
*/
12
12
13
13
export default class RpcError extends StandardError {
14
- constructor ( code , msg , props ) {
14
+ constructor ( code , msg , props = { } ) {
15
15
if ( typeof code != 'number' ) {
16
16
throw new TypeError ( `Non-numeric HTTP code` ) ;
17
17
}
@@ -21,9 +21,9 @@ export default class RpcError extends StandardError {
21
21
msg = null ;
22
22
}
23
23
24
- super ( msg || STATUS_CODES [ code ] , props ) ;
24
+ props . code = code ;
25
25
26
- this . code = code ;
26
+ super ( msg || STATUS_CODES [ code ] , props ) ;
27
27
}
28
28
29
29
get status ( ) {
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
import RpcError from '../../src/errors/rpc-error' ;
7
+ import { STATUS_CODES } from 'http' ;
7
8
import should from 'should' ;
8
9
9
10
/**
@@ -47,4 +48,10 @@ describe('RpcError', () => {
47
48
it ( 'should return a well-formatted string representation' , ( ) => {
48
49
new RpcError ( - 32601 , 'Method not found' ) . toString ( ) . should . equal ( 'RpcError: -32601 Method not found' ) ;
49
50
} ) ;
51
+
52
+ it ( 'should return the correct message by its http code' , ( ) => {
53
+ for ( const code in STATUS_CODES ) {
54
+ new RpcError ( Number ( code ) ) . toString ( ) . should . equal ( `RpcError: ${ code } ${ STATUS_CODES [ code ] } ` ) ;
55
+ }
56
+ } ) ;
50
57
} ) ;
You can’t perform that action at this time.
0 commit comments