Do not show information if a url gives 404 NodeJS

0

Good, there is a way to make if this url where you get the license gives 404 instead of giving errors, directly say no license is found or do not show anything, in the console.

getFromGithub: function(allRepos, callback){
		var self = this;

		var apiRequest = api('/repos/' + self.settings.org + '/' + self.repo + '/contents/package.json', {
			token: self.settings.gitToken
		});

		apiRequest.on('data', function(response) {
			self.reposParsed = JSON.stringify(allRepos);

			var packageJSON = new PackageJSON(self.settings, self.reposParsed);
			packageJSON.parseFromString(response.content, function(){
				self.getLicenseTree(packageJSON, function(err){
					if(err)
						return callback(err, null);

					self.licenses = packageJSON.list;

					callback(null, self.licenses);
				});
			});
		});

		apiRequest.on('error', function(err) {
			console.log(err);
			callback(err, null);
		});
	},
    
asked by Santiago D'Antuoni 30.11.2016 в 18:10
source

1 answer

1

You must add the following line to your router, depending on what your server's variable is called in this case, app. If you can not find the route, you will receive error 404 in your Nvegador

app.get('*', function(req, res){
  res.send('Pagina No Encontrada', 404);
});
    
answered by 30.11.2016 в 18:13