Socket
Socket
Sign inDemoInstall

@superrb/netlify-function-helpers

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @superrb/netlify-function-helpers

Helper methods for writing Netlify functions


Version published
Maintainers
2
Install size
4.59 kB
Created

Readme

Source

Netlify Function Helpers

A library of helpers to use when writing Netlify functions.

withCors

A wrapper around the netlify function callback to handle CORS and parse posted data.

Usage
const { withCors, ValidationError } = require('@superrb/netlify-function-helpers')

exports.handler = withCors((data) => {
  // Throw `ValidationError` to respond with an error message and a 400 status code
  if (!data) {
    throw new ValidationError('Missing data')
  }

  // Throw any other error to respond with the error message and a 500 status code
  try {
    doSomething()
  } catch (err) {
    throw new Error('Something went wrong')
  }

  // Return an object, which will be sent to the client as JSON
  return {
    success: true
  }
})

FAQs

Last updated on 21 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc