Socket
Socket
Sign inDemoInstall

@superrb/netlify-function-helpers

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@superrb/netlify-function-helpers

Helper methods for writing Netlify functions


Version published
Weekly downloads
2
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 21 Feb 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc