@@ -14,6 +14,7 @@ var errors = require('../errors');
14
14
15
15
var BadDigestError = errors . BadDigestError ;
16
16
var RequestEntityTooLargeError = errors . RequestEntityTooLargeError ;
17
+ var PayloadTooLargeError = errors . PayloadTooLargeError ;
17
18
18
19
var MD5_MSG = 'Content-MD5 \'%s\' didn\'t match \'%s\'' ;
19
20
@@ -56,7 +57,7 @@ function createBodyWriter(req) {
56
57
* reads the body of the request.
57
58
* @public
58
59
* @function bodyReader
59
- * @throws {BadDigestError | RequestEntityTooLargeError }
60
+ * @throws {BadDigestError | PayloadTooLargeError }
60
61
* @param {Object } options an options object
61
62
* @returns {Function }
62
63
*/
@@ -86,12 +87,23 @@ function bodyReader(options) {
86
87
}
87
88
88
89
function done ( ) {
90
+ var errorMessage ;
89
91
bodyWriter . end ( ) ;
90
92
91
93
if ( maxBodySize && bytesReceived > maxBodySize ) {
92
94
var msg = 'Request body size exceeds ' +
93
95
maxBodySize ;
94
- next ( new RequestEntityTooLargeError ( msg ) ) ;
96
+
97
+ // Between Node 0.12 and 4 http status code messages changed
98
+ // RequestEntityTooLarge was changed to PayloadTooLarge
99
+ // this check is to maintain backwards compatibility
100
+ if ( PayloadTooLargeError !== undefined ) {
101
+ errorMessage = new PayloadTooLargeError ( msg ) ;
102
+ } else {
103
+ errorMessage = new RequestEntityTooLargeError ( msg ) ;
104
+ }
105
+
106
+ next ( errorMessage ) ;
95
107
return ;
96
108
}
97
109
@@ -101,7 +113,8 @@ function bodyReader(options) {
101
113
}
102
114
103
115
if ( hash && md5 !== ( digest = hash . digest ( 'base64' ) ) ) {
104
- next ( new BadDigestError ( MD5_MSG , md5 , digest ) ) ;
116
+ errorMessage = new BadDigestError ( MD5_MSG , md5 , digest ) ;
117
+ next ( errorMessage ) ;
105
118
return ;
106
119
}
107
120
0 commit comments