@@ -425,6 +425,17 @@ describe('Boom', () => {
425
425
} ) ;
426
426
} ) ;
427
427
428
+ const utilities = [ 'badRequest' , 'unauthorized' , 'forbidden' , 'notFound' , 'methodNotAllowed' ,
429
+ 'notAcceptable' , 'proxyAuthRequired' , 'clientTimeout' , 'conflict' ,
430
+ 'resourceGone' , 'lengthRequired' , 'preconditionFailed' , 'entityTooLarge' ,
431
+ 'uriTooLong' , 'unsupportedMediaType' , 'rangeNotSatisfiable' , 'expectationFailed' ,
432
+ 'badData' , 'preconditionRequired' , 'tooManyRequests' ,
433
+
434
+ // 500s
435
+ 'internal' , 'notImplemented' , 'badGateway' , 'serverUnavailable' ,
436
+ 'gatewayTimeout' , 'badImplementation'
437
+ ] ;
438
+
428
439
describe ( 'badRequest()' , ( ) => {
429
440
430
441
it ( 'returns a 400 error statusCode' , ( ) => {
@@ -1055,25 +1066,22 @@ describe('Boom', () => {
1055
1066
}
1056
1067
} ) ;
1057
1068
} ) ;
1058
- } ) ;
1059
1069
1060
- describe ( 'stack trace ', ( ) => {
1070
+ it ( 'uses data with Error as cause ', ( ) => {
1061
1071
1062
- const helpers = [ 'badRequest' , 'unauthorized' , 'forbidden' , 'notFound' , 'methodNotAllowed' ,
1063
- 'notAcceptable' , 'proxyAuthRequired' , 'clientTimeout' , 'conflict' ,
1064
- 'resourceGone' , 'lengthRequired' , 'preconditionFailed' , 'entityTooLarge' ,
1065
- 'uriTooLong' , 'unsupportedMediaType' , 'rangeNotSatisfiable' , 'expectationFailed' ,
1066
- 'badData' , 'preconditionRequired' , 'tooManyRequests' ,
1072
+ const insideErr = new Error ( 'inside' ) ;
1073
+ const err = Boom . badImplementation ( 'my message' , insideErr ) ;
1074
+ expect ( err . data ) . to . not . exist ( ) ;
1075
+ expect ( err . cause ) . to . shallow . equal ( insideErr ) ;
1076
+ } ) ;
1077
+ } ) ;
1067
1078
1068
- // 500s
1069
- 'internal' , 'notImplemented' , 'badGateway' , 'serverUnavailable' ,
1070
- 'gatewayTimeout' , 'badImplementation'
1071
- ] ;
1079
+ describe ( 'stack trace' , ( ) => {
1072
1080
1073
1081
it ( 'should omit lib' , ( ) => {
1074
1082
1075
- for ( const helper of helpers ) {
1076
- const err = Boom [ helper ] ( ) ;
1083
+ for ( const name of utilities ) {
1084
+ const err = Boom [ name ] ( ) ;
1077
1085
expect ( err . stack ) . to . not . match ( / ( \/ | \\ ) l i b ( \/ | \\ ) i n d e x \. j s / ) ;
1078
1086
}
1079
1087
} ) ;
@@ -1082,10 +1090,10 @@ describe('Boom', () => {
1082
1090
1083
1091
const captureStackTrace = Error . captureStackTrace ;
1084
1092
1085
- for ( const helper of helpers ) {
1093
+ for ( const name of utilities ) {
1086
1094
try {
1087
1095
Error . captureStackTrace = undefined ;
1088
- var err = Boom [ helper ] ( ) ;
1096
+ var err = Boom [ name ] ( ) ;
1089
1097
}
1090
1098
finally {
1091
1099
Error . captureStackTrace = captureStackTrace ;
@@ -1098,35 +1106,7 @@ describe('Boom', () => {
1098
1106
1099
1107
describe ( 'method with error object instead of message' , ( ) => {
1100
1108
1101
- [
1102
- 'badRequest' ,
1103
- 'unauthorized' ,
1104
- 'forbidden' ,
1105
- 'notFound' ,
1106
- 'methodNotAllowed' ,
1107
- 'notAcceptable' ,
1108
- 'proxyAuthRequired' ,
1109
- 'clientTimeout' ,
1110
- 'conflict' ,
1111
- 'resourceGone' ,
1112
- 'lengthRequired' ,
1113
- 'preconditionFailed' ,
1114
- 'entityTooLarge' ,
1115
- 'uriTooLong' ,
1116
- 'unsupportedMediaType' ,
1117
- 'rangeNotSatisfiable' ,
1118
- 'expectationFailed' ,
1119
- 'badData' ,
1120
- 'preconditionRequired' ,
1121
- 'tooManyRequests' ,
1122
- 'internal' ,
1123
- 'notImplemented' ,
1124
- 'badGateway' ,
1125
- 'serverUnavailable' ,
1126
- 'gatewayTimeout' ,
1127
- 'badImplementation'
1128
- ] . forEach ( ( name ) => {
1129
-
1109
+ for ( const name of utilities ) {
1130
1110
it ( `uses stringified error as message` , ( ) => {
1131
1111
1132
1112
const error = new Error ( 'An example mongoose validation error' ) ;
@@ -1135,7 +1115,7 @@ describe('Boom', () => {
1135
1115
expect ( err . cause ) . to . not . exist ( ) ;
1136
1116
expect ( err . message ) . to . equal ( error . toString ( ) ) ;
1137
1117
} ) ;
1138
- } ) ;
1118
+ }
1139
1119
} ) ;
1140
1120
1141
1121
describe ( 'reformat()' , ( ) => {
0 commit comments