350 matches across 25 files for error lang:JavaScript lang:JavaScript
snippet_mode: grep · sorted by relevance
examples/auth/index.js JAVASCRIPT 5 matches view file →
29
30app.use(function(req, res, next){
31 var err = req.session.error;
32 var msg = req.session.success;
33 delete req.session.error;
· · ·
33 delete req.session.error;
34 delete req.session.success;
35 res.locals.message = '';
· · ·
36 if (err) res.locals.message = '<p class="msg error">' + err + '</p>';
37 if (msg) res.locals.message = '<p class="msg success">' + msg + '</p>';
38 next();
· · ·
77 next();
78 } else {
79 req.session.error = 'Access denied!';
80 res.redirect('/login');
81 }
· · ·
120 });
121 } else {
122 req.session.error = 'Authentication failed, please check your '
123 + ' username and password.'
124 + ' (use "tj" and "foobar")';
examples/downloads/index.js JAVASCRIPT 1 matches view file →
27 res.download(req.params.file.join('/'), { root: FILES_DIR }, function (err) {
28 if (!err) return; // file sent
29 if (err.status !== 404) return next(err); // non-404 error
30 // file for download not found
31 res.statusCode = 404;
examples/error-pages/index.js JAVASCRIPT 20 matches · showing 5 view file →
15app.set('view engine', 'ejs');
16
17// our custom "verbose errors" setting
18// which we can use in the templates
19// via settings['verbose errors']
· · ·
19// via settings['verbose errors']
20app.enable('verbose errors');
21
· · ·
20app.enable('verbose errors');
21
22// disable them in production
· · ·
23// use $ NODE_ENV=production node examples/error-pages
24if (app.settings.env === 'production') app.disable('verbose errors')
25
· · ·
24if (app.settings.env === 'production') app.disable('verbose errors')
25
26silent || app.use(logger('dev'));
+ 15 more matches in this file
examples/error/index.js JAVASCRIPT 11 matches · showing 5 view file →
12if (!test) app.use(logger('dev'));
13
14// error handling middleware have an arity of 4
15// instead of the typical (req, res, next),
16// otherwise they behave exactly like regular
· · ·
18// in different orders etc.
19
20function error(err, req, res, next) {
21 // log it
22 if (!test) console.error(err.stack);
· · ·
22 if (!test) console.error(err.stack);
23
24 // respond with 500 "Internal Server Error".
· · ·
24 // respond with 500 "Internal Server Error".
25 res.status(500);
26 res.send('Internal Server Error');
· · ·
26 res.send('Internal Server Error');
27}
28
+ 6 more matches in this file
examples/mvc/index.js JAVASCRIPT 3 matches view file →
17app.set('view engine', 'ejs');
18
19// set views for error and 404 pages
20app.set('views', path.join(__dirname, 'views'));
21
· · ·
78app.use(function(err, req, res, next){
79 // log it
80 if (!module.parent) console.error(err.stack);
81
82 // error page
· · ·
82 // error page
83 res.status(500).render('5xx');
84});
examples/mvc/lib/boot.js JAVASCRIPT 1 matches view file →
61 default:
62 /* istanbul ignore next */
63 throw new Error('unrecognized route: ' + name + '.' + key);
64 }
65
examples/params/index.js JAVASCRIPT 3 matches view file →
5 */
6
7var createError = require('http-errors')
8var express = require('../../');
9var app = module.exports = express();
· · ·
24 req.params[name] = parseInt(num, 10);
25 if( isNaN(req.params[name]) ){
26 next(createError(400, 'failed to parseInt '+num));
27 } else {
28 next();
· · ·
37 next();
38 } else {
39 next(createError(404, 'failed to find user'));
40 }
41});
examples/resource/index.js JAVASCRIPT 2 matches view file →
44 },
45 show: function(req, res){
46 res.send(users[req.params.id] || { error: 'Cannot find user' });
47 },
48 destroy: function(req, res, id){
· · ·
70// curl http://localhost:3000/users -- responds with all users
71// curl http://localhost:3000/users/1 -- responds with user 1
72// curl http://localhost:3000/users/4 -- responds with error
73// curl http://localhost:3000/users/1..3 -- responds with several users
74// curl -X DELETE http://localhost:3000/users/1 -- deletes the user
examples/route-middleware/index.js JAVASCRIPT 5 matches view file →
30 next();
31 } else {
32 next(new Error('Failed to load user ' + req.params.id));
33 }
34}
· · ·
41 } else {
42 // You may want to implement specific exceptions
43 // such as UnauthorizedError or similar so that you
44 // can handle these can be special-cased in an error handler
45 // (view ./examples/pages for this)
· · ·
44 // can handle these can be special-cased in an error handler
45 // (view ./examples/pages for this)
46 next(new Error('Unauthorized'));
· · ·
46 next(new Error('Unauthorized'));
47 }
48}
· · ·
53 next();
54 } else {
55 next(new Error('Unauthorized'));
56 }
57 }
examples/route-separation/user.js JAVASCRIPT 1 matches view file →
18 next();
19 } else {
20 var err = new Error('cannot find user ' + id);
21 err.status = 404;
22 next(err);
examples/search/index.js JAVASCRIPT 2 matches view file →
41 await db.sAdd('cat', 'luna');
42 } catch (err) {
43 console.error('Error initializing Redis:', err);
44 process.exit(1);
45 }
· · ·
55 .then((vals) => res.send(vals))
56 .catch((err) => {
57 console.error(`Redis error for query "${query}":`, err);
58 next(err);
59 });
examples/view-locals/index.js JAVASCRIPT 1 matches view file →
20
21// naive nesting approach,
22// delegating errors to next(err)
23// in order to expose the "count"
24// and "users" locals
examples/web-service/index.js JAVASCRIPT 9 matches · showing 5 view file →
9var app = module.exports = express();
10
11// create an error with .status. we
12// can then use the property in our
13// custom error handler (Connect respects this prop as well)
· · ·
13// custom error handler (Connect respects this prop as well)
14
15function error(status, msg) {
· · ·
15function error(status, msg) {
16 var err = new Error(msg);
17 err.status = status;
· · ·
16 var err = new Error(msg);
17 err.status = status;
18 return err;
· · ·
32
33 // key isn't present
34 if (!key) return next(error(400, 'api key required'));
35
36 // key is invalid
+ 4 more matches in this file
lib/application.js JAVASCRIPT 12 matches · showing 5 view file →
144 * Dispatch a req, res pair into the application. Starts pipeline processing.
145 *
146 * If no callback is provided, then default error handlers will respond
147 * in the event of an error bubbling through the stack.
148 *
· · ·
147 * in the event of an error bubbling through the stack.
148 *
149 * @private
· · ·
154 var done = callback || finalhandler(req, res, {
155 env: this.get('env'),
156 onerror: logerror.bind(this)
157 });
158
· · ·
211
212 if (fns.length === 0) {
213 throw new TypeError('app.use() requires a middleware function')
214 }
215
· · ·
294app.engine = function engine(ext, fn) {
295 if (typeof fn !== 'function') {
296 throw new Error('callback function required');
297 }
298
+ 7 more matches in this file
lib/request.js JAVASCRIPT 2 matches view file →
64req.header = function header(name) {
65 if (!name) {
66 throw new TypeError('name argument is required to req.get');
67 }
68
· · ·
69 if (typeof name !== 'string') {
70 throw new TypeError('name must be a string to req.get');
71 }
72
lib/response.js JAVASCRIPT 23 matches · showing 5 view file →
14
15var contentDisposition = require('content-disposition');
16var createError = require('http-errors')
17var deprecate = require('depd')('express');
18var encodeUrl = require('encodeurl');
· · ·
53 *
54 * Expects an integer value between 100 and 999 inclusive.
55 * Throws an error if the provided status code is not an integer or if it's outside the allowable range.
56 *
57 * @param {number} code - The HTTP status code to set.
· · ·
58 * @return {ServerResponse} - Returns itself for chaining methods.
59 * @throws {TypeError} If `code` is not an integer.
60 * @throws {RangeError} If `code` is outside the range 100 to 999.
61 * @public
· · ·
60 * @throws {RangeError} If `code` is outside the range 100 to 999.
61 * @public
62 */
· · ·
65 // Check if the status code is not an integer
66 if (!Number.isInteger(code)) {
67 throw new TypeError(`Invalid status code: ${JSON.stringify(code)}. Status code must be an integer.`);
68 }
69 // Check if the status code is outside of Node's valid range
+ 18 more matches in this file
lib/utils.js JAVASCRIPT 2 matches view file →
146 break;
147 default:
148 throw new TypeError('unknown value for etag function: ' + val);
149 }
150
· · ·
178 break;
179 default:
180 throw new TypeError('unknown value for query parser function: ' + val);
181 }
182
lib/view.js JAVASCRIPT 2 matches view file →
59
60 if (!this.ext && !this.defaultEngine) {
61 throw new Error('No default engine was specified and no extension was provided.');
62 }
63
· · ·
82
83 if (typeof fn !== 'function') {
84 throw new Error('Module "' + mod + '" does not provide a view engine.')
85 }
86
test/Route.js JAVASCRIPT 11 matches · showing 5 view file →
126
127 route.get(function () {
128 throw new Error('not me!');
129 })
130
· · ·
168 })
169
170 describe('errors', function(){
171 it('should handle errors via arity 4 functions', function(done){
172 var req = { order: '', method: 'GET', url: '/' };
· · ·
171 it('should handle errors via arity 4 functions', function(done){
172 var req = { order: '', method: 'GET', url: '/' };
173 var route = new Route('');
· · ·
174
175 route.all(function(req, res, next){
176 next(new Error('foobar'));
177 });
178
· · ·
200
201 route.all(function () {
202 throw new Error('foobar');
203 });
204
+ 6 more matches in this file
test/Router.js JAVASCRIPT 18 matches · showing 5 view file →
46
47 router.use(function (req, res) {
48 throw new Error('should not be called')
49 });
50
· · ·
56
57 router.use(function (req, res) {
58 throw new Error('should not be called')
59 })
60
· · ·
68 var use = false
69
70 route.post(function (req, res, next) { next(new Error('should not run')) })
71 route.all(function (req, res, next) {
72 all = true
· · ·
73 next()
74 })
75 route.get(function (req, res, next) { next(new Error('should not run')) })
76
77 router.get('/foo', function (req, res, next) { next(new Error('should not run')) })
· · ·
77 router.get('/foo', function (req, res, next) { next(new Error('should not run')) })
78 router.use(function (req, res, next) {
79 use = true
+ 13 more matches in this file
test/acceptance/auth.js JAVASCRIPT 2 matches view file →
23 })
24
25 it('should display login error for bad user', function (done) {
26 request(app)
27 .post('/login')
· · ·
38 })
39
40 it('should display login error for bad password', function (done) {
41 request(app)
42 .post('/login')
test/acceptance/error-pages.js JAVASCRIPT 3 matches view file →
1
2var app = require('../../examples/error-pages')
3 , request = require('supertest');
4
· · ·
5describe('error-pages', function(){
6 describe('GET /', function(){
7 it('should respond with page list', function(done){
· · ·
53 .get('/404')
54 .set('Accept','application/json')
55 .expect(404, { error: 'Not found' }, done)
56 })
57 })
test/acceptance/error.js JAVASCRIPT 2 matches view file →
1
2var app = require('../../examples/error')
3 , request = require('supertest');
4
· · ·
5describe('error', function(){
6 describe('GET /', function(){
7 it('should respond with 500', function(done){
test/acceptance/markdown.js JAVASCRIPT 1 matches view file →
13
14 describe('GET /fail',function(){
15 it('should respond with an error', function(done){
16 request(app)
17 .get('/fail')
test/acceptance/mvc.js JAVASCRIPT 1 matches view file →
94
95 describe('PUT /user/:id', function(){
96 it('should 500 on error', function(done){
97 request(app)
98 .put('/user/1')
Search syntax
auth loginboth terms (AND is implicit)
auth OR logineither term
NOT path:vendorexclude matches
"exact phrase"quoted exact match
/func\s+Test/regex
handler~1fuzzy (Levenshtein 1)
file:*_test.gofilename glob
path:pkg/auth/**full path glob
lang:golanguage filter

Search any public repo from your terminal

This page calls POST /api/v1/code_search. Same tool, available over MCP for Claude/Cursor/Copilot.