1.0.7 • Published 3 years ago

hans-http-handlers v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

hans-http-handlers

http handlers for express

Table of contents

Installing Add the package to your project

npm i hans-http-handlers

using yarn

yarn add hans-http-handlers

Example

Export handlers from hans-http-handlers

const {error500, error401, status201} = require('hans-http-handlers')

using TypeScript

import {error500, error401, status201} from 'hans-http-handlers'
async function anyController(res: Response, req: Request) {
    try {
        
        
        if ('some unauthorized condition') return error401(res)

        const data = {}
        
        status201(res, data)
    } catch (e: any) {
        error500('any controller', res, e, __filename)
    }

Handlers

    status200(res: Response, data: Record<string, any> | null)
    status200Message(res: Response, message: string)
    status201(res: Response, data: Record<string, any>)
    error400(res: Response, message?: string, additionalErrors?: Record<string, any>)
    error401(res: Response, message?: string)
    error403(res: Response, message?: string)
    error500(initiator: string, res: Response, e: any, file: string)
1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago