jaune-web
Version:
88 lines (73 loc) • 2.06 kB
text/coffeescript
###*
* Source code for Http utility.
* Alvaro Juste
###
'use strict'
# 3rd
lodash = require 'lodash'
{bind} = lodash
{isFunction} = lodash
# jaune
{HttpCode} = require '../http'
{Unauthorized} = HttpCode
{InsufficientTrustLevel} = HttpCode
{NotFound} = HttpCode
{BadRequest} = HttpCode
{NotModified} = HttpCode
{NotAcceptable} = HttpCode
{InternalServerError} = HttpCode
{Ok} = HttpCode
###*
* Get util from context
* {Object} ctx The context
###
util = (ctx) -> ctx.jaune.engine().Http.Util
###*
* Get app
* {Object} ctx The context
###
app = (ctx) -> ctx.jaune.app()
###*
* End with anauthorized http code
###
unauthorized = ->
{error} = app(this).getHandlers
error.call this, statusCode: Unauthorized if isFunction error
util(this).endWithCode this, Unauthorized
###*
* End with insufficient trust level http code
###
insufficientTrustLevel = -> util(this).endWithCode this, InsufficientTrustLevel
###*
* End with not found http code
###
notFound = -> util(this).endWithCode this, NotFound
###*
* End bad request http code
###
badRequest = -> util(this).endWithCode this, BadRequest
###*
* End with not modified http code
###
notModified = -> util(this).endWithCode this, NotModified
###*
* End with not acceptable code
###
notAcceptable = -> util(this).endWithCode this, NotAcceptable
###*
* End with error http code
###
error = -> util(this).endWithCode this, InternalServerError
###*
* End with ok http code
###
ok = -> util(this).endWithCode this, Ok
module.exports = (context) ->
unauthorized: bind unauthorized, context
insufficientTrustLevel: bind insufficientTrustLevel, context
notAcceptable: bind notAcceptable, context
notFound: bind notFound, context
notModified: bind notModified, context
badRequest: bind badRequest, context
error: bind error, context
ok: bind ok, context