what is best for use between sql and nosql database? - error-handling

[nodemon] starting node index.js
listening bike port
C:\progects\bikestore-different-brand-server\node_modules\bson\lib\error.js:41
var _this = _super.call(this, message) || this;
^
BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new BSONTypeError (C:\progects\bikestore-different-brand-server\node_modules\bson\lib\error.js:41:28)
at new ObjectId (C:\progects\bikestore-different-brand-server\node_modules\bson\lib\objectid.js:66:23)
at ObjectId (C:\progects\bikestore-different-brand-server\node_modules\bson\lib\objectid.js:26:20)
at C:\progects\bikestore-different-brand-server\index.js:32:27
at Layer.handle [as handle_request] (C:\progects\bikestore-different-brand-server\node_modules\express\lib\router\layer.js:95:5)
at next (C:\progects\bikestore-different-brand-server\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\progects\bikestore-different-brand-server\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\progects\bikestore-different-brand-server\node_modules\express\lib\router\layer.js:95:5)
at C:\progects\bikestore-different-brand-server\node_modules\express\lib\router\index.js:284:15
at param (C:\progects\bikestore-different-brand-server\node_modules\express\lib\router\index.js:365:14)
[nodemon] app crashed - waiting for file changes before starting...

Related

Jsonwebtoken Verify is causing a 500 server error in Express

I'm trying to verify/decode JWTs in my application but am running into an issue, and I have no idea why. Here is the function which is supposed to achieve this, but is creating a 500 server error:
exports.index = (req, res, next) => {
let token = req.headers.authorization;
let decoded = jsonwebtoken.verify(token, process.env.SECRET);
console.log(decoded);
res.send(decoded);
}
req.headers.authorization is correctly storing and delivering the Bearer token, and process.env.SECRET is the same key that was used to sign the token. I am importing the jsonwebtoken library. I'm stumped. Any help is appreciated.
EDIT: Just wrapped the function in a try/catch and the error that is raised is:
JsonWebTokenError: invalid token
at Object.module.exports [as verify] (/Users/-------/repos/sosh/node_modules/jsonwebtoken/verify.js:75:17)
at exports.index (/Users/-------/repos/sosh/controllers/soshController.js:15:32)
at Layer.handle [as handle_request] (/Users/--------/repos/sosh/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/-------/repos/sosh/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/--------/repos/sosh/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/-------/repos/sosh/node_modules/express/lib/router/layer.js:95:5)
at /Users/-------/repos/sosh/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/------/repos/sosh/node_modules/express/lib/router/index.js:335:12)
at next (/Users/-------/repos/sosh/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/Users/------/repos/sosh/node_modules/express/lib/router/index.js:174:3)
I'm wondering why it says invalid token - I use this same token in my JWT authentication strategy and it works fine. Its formatted as "Bearer j5asdj........".

MerkleTreeJS - Leaf resolve error for whitelist verification

We are using MerkleTreeJS to save our community gas fees when minting our NFTs. However, when we send the proof to the contract we get this error:
index.js:238 Uncaught (in promise) TypeError: t.substring is not a function
at c.formatParam (index.js:238:23)
at index.js:217:36
at Array.map (<anonymous>)
at c.formatParam (index.js:217:22)
at index.js:99:22
at Array.map (<anonymous>)
at c.encodeParameters (index.js:93:21)
at index.js:462:20
at Array.map (<anonymous>)
at Object.y._encodeMethodABI (index.js:461:8)
Do you have any idea how we can resolve the array correctly?
This is our code:
const leaves = [
"0x9811e43A71C85CC5f9BdA9822A7459d43A932dd9",
"0x0b371Cf8550923F67e90e5Bb26371e7A7b085b27",
"0xdc0cf0dFF9569209ba0F433e34743A8027A3c9E8",
"0xc4702bfea6410c082f3908fa270b3730fbc33e38"
].map(x => SHA256(x));
const tree = new MerkleTree(leaves, SHA256);
const root = tree.getRoot().toString('hex');
const leaf = SHA256(localStorage.userWallet);
proof = tree.getProof(leaf);
if (tree.verify(proof, leaf, root) === true) {
// address whitelisted
} else {
// not on whitelist
}

Reference Error with module exports event discord.js

I am very confused by this error. In my code I have /events/ and /commands/ this is in /events/ I made sure that everything else works but this I can't figure out. The code down below is meant to work as a server count for a website. Anybody know? Thank you.
const Discord = require('discord.js');
var db = require('mysql');
var con = db.createConnection({
host: "localhost",
user: "",
password: "",
database: ""
});
module.exports = (client, guildCreate) => {
//welcome embed
const welcomeEmbed = new Discord.MessageEmbed()
.setColor('#858884')
.setTitle('Hello!')
.setAuthor('DHL Bot', 'https://cdn.discordapp.com/app-icons/708717412391845988/967e1b05f7b8aeca1d6b4649dc5530c8.png')
.setDescription(`Hello I am DHL, I am devoloped by Den#0762. Please do !setup. For support you can join our support server https://discord.com/invite`)
.setTimestamp()
.setFooter('By: Den#0762', 'https://cdn.discordapp.com/avatars/407206318911258628/e972b589e0ea4c45064d39b0380d77fd.png')
guild.owner.send(welcomeEmbed)
//db for scount
con.connect(function(err) {
if (err) throw err;
var sql = "UPDATE scount SET servercount = servercount + 1";
con.query(sql, function (err, result) {
console.log(result.affectedRows + " new server");
});
});
}
(node:1949) UnhandledPromiseRejectionWarning: ReferenceError: guild is not defined
at module.exports (/root/dc/DHL/events/guildCreate.js:23:1)
at Client.emit (events.js:315:20)
at Object.module.exports [as GUILD_CREATE] (/root/node_modules/discord.js/src/client/websocket/handlers/GUILD_CREATE.js:33:14)
at WebSocketManager.handlePacket (/root/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/root/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/root/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/root/node_modules/ws/lib/event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (/root/node_modules/ws/lib/websocket.js:797:20)
at Receiver.emit (events.js:315:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1949) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1949) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
You're referencing guild, but it isn't declared. Based on other code I've seen, I think you need something along these lines:
module.exports = (client, guildCreate) => {
//welcome embed
const welcomeEmbed = new Discord.MessageEmbed() [...]
client.on("guildCreate", guild => {
guild.owner.send(welcomeEmbed)
});
[...]

Aurelia startup error - Invalid resource path: function Compose

After upgrading my Aurelia Framework in my application via:
"aurelia-bootstrapper": "^2.3.0"
I'm getting error at the application startup (stack trace at the bottom).
Returning to:
"aurelia-bootstrapper": "2.2.0"
fixes the error. In release notes for version of Aurelia in question, there is note about additional functionality of setRoot method, but nothing that could be breaking change Aurelia Release Notes - June 2018.
I just use default:
aurelia.start().then(() => aurelia.setRoot());
This is details stack trace of startup error:
vendor-bundle.js:1398 Unhandled rejection Error: Invalid resource path [function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) {
_initDefineProp(this, 'model', _descriptor, this);
_initDefineProp(this, 'view', _descriptor2, this);
_initDefineProp(this, 'viewModel', _descriptor3, this);
_initDefineProp(this, 'swapOrder', _descriptor4, this);
this.element = element;
this.container = container;
this.compositionEngine = compositionEngine;
this.viewSlot = viewSlot;
this.viewResources = viewResources;
this.taskQueue = taskQueue;
this.currentController = null;
this.currentViewModel = null;
this.changes = Object.create(null);
}]. Resources must be specified as relative module IDs.
at FrameworkConfiguration.globalResources (http://localhost/scripts/vendor-bundle.js:69284:17)
at Object.configure (http://localhost/scripts/vendor-bundle.js:62319:12)
at http://localhost/scripts/vendor-bundle.js:69140:36
From previous event:
at _loadPlugin (http://localhost/scripts/vendor-bundle.js:69138:42)
at http://localhost/scripts/vendor-bundle.js:69131:16
From previous event:
at loadPlugin (http://localhost/scripts/vendor-bundle.js:69130:75)
at next (http://localhost/scripts/vendor-bundle.js:69392:20)
From previous event:
at next (http://localhost/scripts/vendor-bundle.js:69392:56)
at http://localhost/scripts/vendor-bundle.js:69399:16
From previous event:
at FrameworkConfiguration.apply (http://localhost/scripts/vendor-bundle.js:69384:44)
at Aurelia.start (http://localhost/scripts/vendor-bundle.js:69000:39)
at Object.<anonymous> (http://localhost/scripts/app-bundle.js:5811:33)
at step (http://localhost/scripts/app-bundle.js:51:23)
at Object.next (http://localhost/scripts/app-bundle.js:32:53)
at fulfilled (http://localhost/scripts/app-bundle.js:23:58)
From previous event:
at step (http://localhost/scripts/app-bundle.js:25:124)
at http://localhost/scripts/app-bundle.js:26:9
From previous event:
at __awaiter (http://localhost/scripts/app-bundle.js:22:12)
at Object.configure (http://localhost/scripts/app-bundle.js:5793:16)
at http://localhost/scripts/vendor-bundle.js:70930:29
From previous event:
at config (http://localhost/scripts/vendor-bundle.js:70925:56)
at http://localhost/scripts/vendor-bundle.js:70961:14
From previous event:
at bootstrap (http://localhost/scripts/vendor-bundle.js:70960:26)
at http://localhost/scripts/vendor-bundle.js:70947:9
From previous event:
at run (http://localhost/scripts/vendor-bundle.js:70942:61)
at Object.<anonymous> (http://localhost/scripts/vendor-bundle.js:70967:37)
at Object.execCb (http://localhost/scripts/vendor-bundle.js:8724:33)
at Module.check (http://localhost/scripts/vendor-bundle.js:7911:51)
at Module.enable (http://localhost/scripts/vendor-bundle.js:8204:22)
at Object.enable (http://localhost/scripts/vendor-bundle.js:8585:39)
at Module.<anonymous> (http://localhost/scripts/vendor-bundle.js:8189:33)
at http://localhost/scripts/vendor-bundle.js:7162:23
at each (http://localhost/scripts/vendor-bundle.js:7087:31)
at Module.enable (http://localhost/scripts/vendor-bundle.js:8141:17)
at Module.init (http://localhost/scripts/vendor-bundle.js:7816:26)
at http://localhost/scripts/vendor-bundle.js:8488:36
printWarning # vendor-bundle.js:1398

Loopback error - value is not an object

I am using loopback in backend. I am getting this error
Unhandled error for request POST /api/meetups/auth: Error: Value is not an object.
at errorNotAnObject (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/types/object.js:80:13)
at Object.validate (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/types/object.js:51:14)
at Object.fromTypedValue (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/types/object.js:14:22)
at Object.fromSloppyValue (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/types/object.js:41:17)
at HttpContext.buildArgs (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/http-context.js:193:22)
at new HttpContext (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/http-context.js:59:20)
at restStaticMethodHandler (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/rest-adapter.js:457:15)
at Layer.handle [as handle_request] (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/layer.js:95:5)
at /Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/index.js:335:12)
at next (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/index.js:275:10)
at Function.handle
(/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/index.js:174:3)
at router (/Users/ankursharma/Documents/projects/meetupz/node_modules/express/lib/router/index.js:47:12)
I have already searched stackoverflow, but I didnt find answer. Basically, i was trying to use body-parser . I went through one of the stackoverflow thread and implemented its solution. I was able to use body-parser successfully. So, that error has been solved. But, now this error is giving me tough time.
server.js file
'use strict';
var loopback = require('loopback');
var boot = require('loopback-boot');
var bodyParser = require('body-parser');
var multer = require('multer');
var app = module.exports = loopback();
//code for body parsing
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
//app.use(multer()); // for parsing multipart/form-data
//code for body parsing ends
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
In middleware.json, I have updated parse property as well
"parse": {"body-parser#json": {},
"body-parser#urlencoded": {"params": { "extended": true }}},
For some reason, that error has gone. Not sure, may be it will come again. But now, this is the error, I am seeing
Unhandled error for request POST /api/meetups/auth: TypeError: cb is not a function
at Function.Meetups.auth (/Users/ankursharma/Documents/projects/meetupz/common/models/meetups.js:117:3)
at SharedMethod.invoke (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/shared-method.js:270:25)
at HttpContext.invoke (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/http-context.js:297:12)
at phaseInvoke (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/remote-objects.js:677:9)
at runHandler (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/lib/phase.js:135:5)
at iterate (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)
at Object.async.eachSeries (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/node_modules/async/lib/async.js:162:9)
at runHandlers (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/lib/phase.js:144:13)
at iterate (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)
at /Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/node_modules/async/lib/async.js:157:25
at /Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/node_modules/async/lib/async.js:154:25
at execStack (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/remote-objects.js:522:7)
at RemoteObjects.execHooks (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/remote-objects.js:526:10)
at phaseBeforeInvoke (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/lib/remote-objects.js:673:10)
at runHandler (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/lib/phase.js:135:5)
at iterate (/Users/ankursharma/Documents/projects/meetupz/node_modules/strong-remoting/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)
check if your filters or your URL has black spaces i.e. %20, or anything wrong with the filter or url.
Loopback 3 makes a difference between array and object. You have to check your data type. See https://github.com/strongloop/strong-remoting/issues/360 for more information.
I was facing the same error but in my case it was due to a model property data length.The property was type object and a small dataLength which caused faulty record in my sql Model table.I have to Manually delete those faulty records and increase the dataLength of that property too.
Restart the app