Is nestjs caching or something - nestjs

I have a controller FooController with 3 routes
#Post
#Get
#Get('/:id')
Even if I restart server, my controller isn't updated.
I edit something, it's updated after like 50 restarts, it look like nestjs is hard caching something but I don't find anything.
10 minuts ago:
throw new HttpException({ message: 'Failed to get surveys' }, HttpStatus.INTERNAL_SERVER_ERROR);
5 minuts ago:
throw new HttpException({ error: 'test, message: 'Failed to get surveys' }, HttpStatus.INTERNAL_SERVER_ERROR);
I still get only { message } in my response.
I remove #Get('/id') and restart again and again server, my front still can make #Get('/id') request and it return the survey, wtf is this ?
I need to spam restart till I get error, it's so boring!
Any idea ?

Related

Updated API works locally but not on Heroku even when its using updated code

I'm revisiting an old note taking project and updated the response from a post request to include the id of the new note instead of just a message with "new note created" like before. I pushed the changes to github and the heroku auto-deploy build succeeded.
My issue is that I get the proper response of {id: 'id', message: 'message'} when I test the api locally but heroku gives me the old response of {message: 'message'} like its using the older version of the api. There are no bad statuses or error messages and the build is using the newest code from git as far as I'm aware. Any idea why this is happening? I feel like I might be missing something obvious.
The updated api call looks like this:
server.post('/api/notes', (req, res) => {
const note = req.body;
knex
.insert(note)
.into('notes')
.then(response => {
res
.status(201)
.json({ id: response[0], message: 'New note successfully created' });
})
.catch(err => {
res.status(500).json({ message: 'Error creating note' });
});
});
The old code is the same except the json response doesn't have the 'id' property.
Also just to show heroku is using the latest code:
pic of latest git commit
pic of heroku deploy message
UPDATE: So I made minor changes to test and they do in fact get updated. I did a console.log and realized the response[0] variable prints as undefined from the heroku logs but it prints just fine locally. I have no idea what could be causing this.
Ok so I actually solved the issue. Turns out I needed to edit my .insert(note) call to look like this .insert(note, ['id']) and then send the json as {id: response[0].id, message: ''}. Locally response was returning the id and on heroku it was returning something totally different. I also realized that the local database I was using was sqlite3 and heroku is using postgres. I'm guessing the returned response variable is different when using one or the other.
Not solving your problem but might help to debug:
You can install the heroku CLI: https://devcenter.heroku.com/articles/heroku-cli and login into the server with heroku run bash -a <appname>. You could check if the right code is uploaded, your node version, and the version of the node_modules in question.

catch never outputs the console even though I know it's failing

I have my mongodb service stopped, so I know that my front end is not connected to my DB. I am using react and express.
Upon my app starting, I want to indicate that to the user somehow the server is offline so I figured if my original get call for users fails, then the server is offline.
I'm doing a simple call:
componentDidMount () {
axios.get ('/api/users')
.then ((res) => this.setState(
{ users : res.data }
))
.catch ((error) => {
//console.error(error);
console.log('error found : offline');
});
}
But nothing happens in situation. I never get the catch call for the console. Am I going about this wrong? I'm new to backend so this is all a learning experience for me.
I was going to set a failed flag and then render a display error for the user and then retry the connection every 1500ms or something (is that bad programming?).

Meteor - How to handle external API connection errors?

I'm using a few external API's (some in timers, every minute or so) and sometimes I get some connection errors because of network problems or because the external systems are down for some reason. When I get this errors, the app restarts, and if the error persists the app continues restarting.
Any ideas on how can I ignore the connection error and keep the app running?
Code Example:
try {
var req = https.request(options, callback);
req.write(JSON.stringify(params));
req.end();
} catch (e) {
throw e;
}
Based on your code example. You're doing throw e inside your try catch. Essentially, you're catching an error and then throwing the error. Just do console.error(err) or however you want to handle that error, without throwing. This is what will cause your instance to stop.

Silently reporting errors to Papertrail

I'm working with a large Node.js application on Heroku, with logging maintained by Papertrail. I have a central error handling and logging function which, at the moment, just logs an error to the console, displays a generic "An error occurred!" dialog, and redirects a client to a specific page (depending on where the error occurred). But neither Papertrail nor Heroku detect this as a real error, and I don't get any sort of notifications or alerts if and when they occur.
At the moment, this is my function:
utilities.errorLogger = (err) => {
console.error(err);
};
I've tried to throw the error, which works like below:
utilities.errorLogger = (err) => {
throw new Error(err);
};
But then the error is displayed to the client, rather than being redirected away, leaving the end user confused. Similarly, putting the error in a try-catch block does not change anything from what I currently have (the error is logged but not picked up on by Papertrail or Heroku).
utilities.errorLogger = (err) => {
try {
throw new Error(err);
}
catch (err) {
console.error(err);
}
};
How can I silently throw an error for Papertrail and Heroku to pick up on and treat as an error, without needing to send the error to the client? I'd like to be able to silently handle the error and have the reporting go on in the background, rather than sending any of the error details to the client.
Ended up finding out the answer. I'm using KeystoneJS which comes with a default error handler that I hadn't seen before; I've modified it now to just redirect people while still being able to log the error.

Child process and api call in Node

I have a script file in Node js with a function that recursively calls itself after sometime outs.
This function sends out a "message" to which parent is listening.
This parent is nothing but a REST api with basic CRUD operations.
In this file, this is what forking part looks like:
var myBgTask = require('child_process').fork('./server/api/thing/bgTask.js', [], { execArgv: ['--debug=5859']});
myBgTask.on('message', function(data){
//DO SOMETHING
})
Now, when from my angular code, I make a request to update the database, somehow the child process gets interrupted and throws Channel closed error at this line:
process.send({
name: randomThing,
readByUser: false
}, function(err){
console.log("error", err)
if(!err)
setTimeout(autoCreate, randomNumb * 1000);
});
and thus my server stops and I never am able to make http post/put calls.
Strange part is that it throws error only when I am making post or put calls and never with get calls.
I have been trying to debug this but have not been able to find out what the problem is. Can I get some help here on this?

Resources