Skip to content

Instantly share code, notes, and snippets.

@vdel26
Last active August 29, 2015 14:21
Show Gist options
  • Save vdel26/f8406e7ca8990eaea74e to your computer and use it in GitHub Desktop.
Save vdel26/f8406e7ca8990eaea74e to your computer and use it in GitHub Desktop.
errors.lua
local errors = {}
local AUTH_FAILED_STATUS = 403
local AUTH_FAILED_HEADERS = 'text/plain; charset=us-ascii'
local AUTH_FAILED_MESSAGE = 'Authentication failed'
local AUTH_MISSING_STATUS = 403
local AUTH_MISSING_HEADERS = 'text/plain; charset=us-ascii'
local AUTH_MISSING_MESSAGE = 'Authentication parameters missing'
local NO_MATCH_STATUS = 404
local NO_MATCH_HEADERS = 'text/plain; charset=us-ascii'
local NO_MATCH_MESSAGE = 'No rule matched'
function errors.no_credentials()
ngx.status = AUTH_MISSING_STATUS
ngx.header.content_type = AUTH_MISSING_HEADERS
ngx.print(AUTH_MISSING_MESSAGE)
ngx.exit(ngx.HTTP_OK)
end
function errors.authorization_failed()
ngx.status = AUTH_FAILED_STATUS
ngx.header.content_type = AUTH_FAILED_HEADERS
ngx.print(AUTH_FAILED_MESSAGE)
ngx.exit(ngx.HTTP_OK)
end
function errors.no_match()
ngx.status = NO_MATCH_STATUS
ngx.header.content_type = NO_MATCH_HEADERS
ngx.print(NO_MATCH_MESSAGE)
ngx.exit(ngx.HTTP_OK)
end
return errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment