當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Response.sendStatus方法代碼示例

本文整理匯總了TypeScript中express.Response.sendStatus方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.sendStatus方法的具體用法?TypeScript Response.sendStatus怎麽用?TypeScript Response.sendStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在express.Response的用法示例。


在下文中一共展示了Response.sendStatus方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

router.post('/login', function(req: Request, res: Response, next: Function) {
    let username = req.body.username;
    let password = req.body.password;
    let user = UserService.findById(username);
    if(user && (password === user.password)) {
        res.set('jwt', jsonwebtoken.sign({sub: user.id}, 'secret'));
        res.sendStatus(200);
    } else {
        res.sendStatus(403);
    }
});
開發者ID:DaniOtero,項目名稱:jwt-express-demo,代碼行數:11,代碼來源:user.ts

示例2: handleError

	/**
	 * ErrorHandler method for all Request classes.
	 * If the err parameter is of type object the object is logged and error code
	 * 500 is added to the response. If the err parameter is of type number the number
	 * is send as statusCode to the client. If none of these is true statusCode 500 is send
	 * to the client and an 'undefined error' is logged.
	 * @param err error object or statusCode
	 * @param res response object that holds the data send to the client
     */
	handleError(err, res:Response) {
		if (typeof err === 'object') {
			console.error(err);
			res.status(500).send(err.toString());
		} else if (typeof err === 'number') {
			res.sendStatus(err);
		} else {
			console.error('undefined error');
			res.sendStatus(500);
		}
	}
開發者ID:draschke,項目名稱:n-odata-server,代碼行數:20,代碼來源:BaseRequestHandler.ts

示例3: function

module.exports = function (req: Request, res: Response, next: any) {
  // User is allowed, proceed to controller
  var is_auth = req.isAuthenticated();
  if (is_auth) return next();
  // User is not allowed
  return res.sendStatus(401);
};
開發者ID:twicepixels,項目名稱:tp-main-api,代碼行數:7,代碼來源:authenticated.ts

示例4: async

router.post('/', async (req: Request, res: Response, next: NextFunction) => {
    if (!req.body.hasOwnProperty('publicId')) {
        const err = new Error('Request lacked a publicId');
        res.status(400);
        return next(err);
    }

    const publicId = req.body.publicId;

    try {
        await db.markMessagesUnread(
            req.user,
            [publicId],
        );

        const message = await db.getMessage(req.user, publicId);

        publishMessage(req.app, req.user, message);

        res.sendStatus(204);
        return;
    } catch (e) {
        return res.status(500).json(e);
    }
});
開發者ID:lovett,項目名稱:notifier,代碼行數:25,代碼來源:unclear.ts

示例5:

 productService.retrieveProduct(req.params.name).then((product: ProductInstance) => {
   if (product) {
     return res.send(product);
   } else {
     return res.sendStatus(404);
   }
 }).catch((error: Error) => {
開發者ID:natarajanmca11,項目名稱:sequelize-typescript-examples,代碼行數:7,代碼來源:product-router.ts

示例6: ensureUser

function ensureUser(req: Request, res: Response, next: NextFunction) {
  if (req.user) {
    next();
  } else {
    res.sendStatus(401);
  }
}
開發者ID:odetown,項目名稱:golfdraft,代碼行數:7,代碼來源:authMiddleware.ts

示例7:

	}, (status, body) => {
		if (body == null || body == '') {
			res.sendStatus(status);
		} else {
			res.status(status).send(body);
		}
	}, next);
開發者ID:syuilo,項目名稱:accesses,代碼行數:7,代碼來源:express.ts

示例8: async

router.post('/', async (req: Request, res: Response) => {
    const additions: Token[] = [];
    const removals: string[] = [];
    const whitelist = ['webhook'];

    for (const name in req.body) {
        if (whitelist.indexOf(name) === -1) {
            continue;
        }

        removals.push(name);

        if (req.body[name].trim().length === 0) {
            continue;
        }

        const token = new Token('userval', true, name, req.body[name]);

        additions.push(token);
    }

    if (removals.length === 0 && additions.length === 0) {
        res.status(400).send('Nothing to be done');
        return;
    }

    try {
        await db.deleteTokensByKey(req.user, removals);
        await db.addTokens(req.user, additions);
        return res.sendStatus(200);
    } catch (e) {
        return res.status(500).json(e);
    }
});
開發者ID:lovett,項目名稱:notifier,代碼行數:34,代碼來源:services.ts

示例9: async

 get: async (req: RequestEx, res: Response) => {
     let range = req.query.range;
     
     if (req.query.range != null) {
         range = Range
     }
     
     if (range === undefined) {
         range = null;
     }
     
     let amenities: number[]; 
     
     if(_.isArray(req.query.amenities)) {
         amenities = req.query.amenities
     } else if (req.query.amenities != null) {
         amenities = [req.query.amenities]
     } else {
         amenities = [];
     }
     
     const params = {
         query: req.query.q || "",
         range,
         amenities: amenities
     }
     
     try {
         const lodgings = await getClient().manyOrNone(query, params);
         res.send(lodgings);
     } catch (e) {
         console.log(e);
         res.sendStatus(400);
     }
 }
開發者ID:paavohuhtala,項目名稱:lodgist,代碼行數:35,代碼來源:LodgingSearch.ts

示例10: catch

router.get('/', (req: Request, res: Response, next: Function) => {
    try {
        let notes = UserService.findById(req.user.id).notes;
        res.json({notes: notes});
    } catch(err) {
        res.sendStatus(400);
    }
});
開發者ID:DaniOtero,項目名稱:jwt-express-demo,代碼行數:8,代碼來源:notes.ts


注:本文中的express.Response.sendStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。