I've tried many solutions listed here (increasing of memory limit, adding parameterlimit, adding type as 'application/json') to fix this 'Request Entity too large' error (it also returns http code 413). But none of them seem to make this error go away.
The current size of the json can range from 200k up to 400k entities.
Here is the current configuration:
app.use( bodyParser.json({limit: "15360mb", type:'application/json'}) );
app.use(bodyParser.urlencoded({
limit: "15360mb",
extended: true,
parameterLimit:5000000,
type:'application/json'
}));
app.use(bodyParser())
Any ideas on how to increase the limit?
More information
This is the full error message if it helps:
{ Error: Request Entity Too Large
at respond (/home/nodejs/server/node_modules/elasticsearch/src/lib/transport.js:307:15)
at checkRespForFailure (/home/nodejs/server/node_modules/elasticsearch/src/lib/transport.js:266:7)
at HttpConnector.<anonymous> (/home/nodejs/server/node_modules/elasticsearch/src/lib/connectors/http.js:159:7)
at IncomingMessage.bound (/home/nodejs/server/node_modules/lodash/dist/lodash.js:729:21)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1056:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
status: 413,
displayName: 'RequestEntityTooLarge',
message: 'Request Entity Too Large',
path: '/_bulk',
query: {},
body: '<large body here>'
}
Solution
The error was indeed due to wrong configuration on elasticsearch and not nodejs. Manage to fix this by following https://github.com/elastic/elasticsearch-js/issues/241 and setting http.max_content_length: 500mb in elasticsearch.yml.
#ryanlutgen also provided a link for more information about this error here.
https://github.com/elastic/elasticsearch/issues/2902
This issue has been fixed. Thanks for all the input!
If You doesn't solve your issue, bodyParser also has a limit.
You must use
app.use(bodyParser({limit: '4MB'}))
Related
I'm trying to make a mineflayer bot but it seems to keep sending the same error. Here is the code:
const mineflayer = require('mineflayer')
const bot = mineflayer.createBot({
host: 'localhost',
port: ,
username: 'Test_Bot'
})
And here is the error:
Error: Unsupported brand channel name
at getBrandCustomChannelName (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugins/game.js:22:11)
at inject (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugins/game.js:67:24)
at /Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugin_loader.js:41:7
at Array.forEach (<anonymous>)
at injectPlugins (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugin_loader.js:40:16)
at EventEmitter.onInjectAllowed (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugin_loader.js:12:5)
at Object.onceWrapper (node:events:627:28)
at EventEmitter.emit (node:events:513:28)
at Client.next (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/loader.js:124:9)
at Object.onceWrapper (node:events:627:28)
jeonghunchae#2015017 Bots %
Is there any way how I can fix this error?
First I tried to make a lan server in my world and it sent this error. Then I created a private server with online-mod: false but it still sent the same error.
I had the same Problem.
After a lot of research I found that I was not sure if my minecraft Version(1.19.2) was supported by Mineflayer.
After switching to 1.19 the error Message was gone.
I'm new to express, currently if I want to send a response I would do the following
//...
res.json({
status: 200,
message: "success",
data: "something"
})
//...
for all my controllers functions I would do it this way. I guess this is kind of overwhelming so I was thinking if it's possible to make a generalized version of response.
so after some search I found there is 2 ways of achieving this:
1. use a middleware that runs at the end of each route
I found this answer. which made it clear but I think it's a waste of time and my controller then won't be readable enough and I must do the following in every controller function
req.responseObject = response;
return next()
2. override response class of the express itself
this is much promising, but unfortunately after so many tries and following express docs I couldn't get it to work
here is what I've tried so far
I've created this util function here:
//myRes.js
module.exports = function (code, message, payload) {
return this.status(code).json({
status: 'success', // this will be variable according to whatever code I get
code: code,
message: message || '',
payload: payload || '',
});
};
then I've added this line to app.js
// app.js
const express = require('express');
const app = express();
const myRes= require('./utils/myRes');
app.response.send = myRes;
//...
and this is how I use it on my controller
res.send(200, "hello world", [{"key": "value"}])
when I try to run this I got this Error stack
RangeError: Maximum call stack size exceeded
at JSON.stringify (<anonymous>)
at stringify ([project_dir]\node_modules\express\lib\response.js:1123:12)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:260:14)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:267:15)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:267:15)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:267:15)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:267:15)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:267:15)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
at ServerResponse.json ([project_dir]\node_modules\express\lib\response.js:267:15)
at ServerResponse.module.exports [as send] ([project_dir]\src\utils\response.js:2:28)
why JSON.stringify is complaining I haven't used this function on my entire application
also I am not just capped to these 2 solutions you can suggest other ways if you think it's better
clarifying what #Ariel said in the comments
Express response calls send internally refer to this function from express at lines [120, 123, 136] and that was causing a infinite loop that's why it was saying
Maximum call stack size exceeded
so all I needed to do is to change my function name from send to maybe "sends" and that just worked
it was a bad idea trying to overwrite the built in send function
I am trying to make API call from Node.js Expressjs. API call is working fine however after parsing the response to JSON, when I try to access different fields it gives me an error.
I try to log the type of one element of the JSON object to console. First it says Object and then it says undefines (or if try to log the content itself, it gives me an error).
var request = require('request');
const app = express();
//For serving static pages
// app.use(express.static('./static'))
app.get('/', (req, res) =>{
res.send('You have successfully contacted the API')
});
app.get('/:ticker', (req, res) => {
var requestOptions = {
'url': 'https://api.tiingo.com/tiingo/daily/' + req.params.ticker + '/prices?startDate=2019-01-02&token=74e7c9d22c2ffe8e9b5643edc2ef48bbddc6e69e',
'headers': {
'Content-Type': 'application/json'
}
};
request(requestOptions,
function(error, response, body) {
result = JSON.parse(body);
console.log('The type is ' + typeof (result[0].date)) //This statement prints different results twice
res.send(result);
}
);
});
app.listen(process.env.PORT || 3000)
Terminal says:
The type is string
D:\Web Dev Bootcamp\NodeJS-Tutorial\index.js:24
console.log('The type is ' + typeof (result[0].date))
^
TypeError: Cannot read property 'date' of undefined
at Request._callback (D:\Web Dev Bootcamp\NodeJS-Tutorial\index.js:24:60)
at Request.self.callback (D:\Web Dev Bootcamp\NodeJS-Tutorial\node_modules\request\request.js:185:22)
at Request.emit (events.js:314:20)
at Request.<anonymous> (D:\Web Dev Bootcamp\NodeJS-Tutorial\node_modules\request\request.js:1154:10)
at Request.emit (events.js:314:20)
at IncomingMessage.<anonymous> (D:\Web Dev Bootcamp\NodeJS-Tutorial\node_modules\request\request.js:1076:12)
at Object.onceWrapper (events.js:420:28)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1223:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) [nodemon] app crashed - waiting for file changes before starting...
Run a quick console.log(result) to make sure that result is being stored as an Array. I suspect that when you are parsing the JSON it is storing result as an object.
Figured out what the issue was. Actually express was making a request for favicon.ico by itself and during that request apparently result variable was undefined. I simply set up another route for handling favicon request as suggested [here][1]. Now the code is simply logging the result once and I am able to access the fields of JSON object properly.
Edit: as pointed out by a contributor, its the browser thats making the favicon request and 'not' the express.
[1]: Node Express "favicon.ico" not found error
I'm posting some sample data to my Smee endpoint and I am also running a local instance of my ProBot app. I get a bad request in my bot logs and I see this is the Smee response:
{ Error: cannot POST / (400)
at Response.toError (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/response.js:94:15)
at ResponseBase._setStatusProperties (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/response-base.js:123:16)
at new Response (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/response.js:41:8)
at Request._emitResponse (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:752:20)
at IncomingMessage.parser (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:916:38)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
status: 400,
text: 'Required headers missing: x-github-event, x-github-delivery',
method: 'POST',
path: '/' },
How can I get these header values to test with in my app? Not sure if it's me, but the documentation doesn't note this anywhere
I used https://www.freeformatter.com/hmac-generator.html#ad-output to throw in the payload as the body and my secret and the hash was valid!
I have a pretty basic passport setup as you can see below. Every once in a while I get two different errors. TokenError: Code was already redeemed and TokenError: Bad Request for reasons I cannot seem to find.
I've looked around a lot (1 week) for possible solutions but am yet to find one which works.
Do you see anything wrong with the current code?
app.get('/auth/google', redirect, passport.authenticate('google', { scope: ['profile', 'email'] }));
app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/' }),
function(req, res) {
res.redirect('/');
}
);
Here are the two errors:
TokenError: Bad Request
at Strategy.OAuth2Strategy.parseErrorResponse (/app/node_modules/passport-oauth2/lib/strategy.js:320:12)
at Strategy.OAuth2Strategy._createOAuthError (/app/node_modules/passport-oauth2/lib/strategy.js:367:16)
at /app/node_modules/passport-oauth2/lib/strategy.js:166:45
at /app/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/app/node_modules/oauth/lib/oauth2.js:123:9)
at IncomingMessage.<anonymous> (/app/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:85:20)
at IncomingMessage.emit (events.js:179:7)
at endReadableNT (_stream_readable.js:913:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
TokenError: Code was already redeemed.
at Strategy.OAuth2Strategy.parseErrorResponse (/app/node_modules/passport-oauth2/lib/strategy.js:320:12)
at Strategy.OAuth2Strategy._createOAuthError (/app/node_modules/passport-oauth2/lib/strategy.js:367:16)
at /app/node_modules/passport-oauth2/lib/strategy.js:166:45
at /app/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/app/node_modules/oauth/lib/oauth2.js:123:9)
at IncomingMessage.<anonymous> (/app/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:85:20)
at IncomingMessage.emit (events.js:179:7)
at endReadableNT (_stream_readable.js:913:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)