How to use the middy/middlewares.httpErrorHandler function in middy

To help you get started, we’ve selected a few middy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github netlify / cli / src / functions-templates / js / using-middleware / using-middleware.js View on Github external
},
    required: ['body']
  }
}

/* Export inputSchema & outputSchema for automatic documentation */
exports.schema = schema

exports.handler = middy(businessLogic)
  .use(httpHeaderNormalizer())
  // parses the request body when it's a JSON and converts it to an object
  .use(jsonBodyParser())
  // validates the input
  .use(validator({ inputSchema: schema.input }))
  // handles common http errors and returns proper responses
  .use(httpErrorHandler())
github josephluck / internote / services / notes / list.ts View on Github external
import { httpErrorHandler, cors } from "middy/middlewares";
import { encodeResponse } from "@internote/lib/middlewares";
import { success } from "@internote/lib/responses";
import { getUserIdentityId } from "@internote/lib/user";
import { GetHandler } from "@internote/lib/types";
import { listNotesByUserId } from "./db/queries";

const list: GetHandler = async (event, _ctx, callback) => {
  const userId = getUserIdentityId(event);
  const notes = await listNotesByUserId(userId);
  return callback(null, success(notes));
};

export const handler = middy(list)
  .use(encodeResponse())
  .use(httpErrorHandler())
  .use(cors());
github faultline / faultline / src / handlers / occurrencesList.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new OccurrencesListHandler(aws))
        .use(httpHeaderNormalizer())
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github josephluck / internote / services / notes / get.ts View on Github external
import { encodeResponse } from "@internote/lib/middlewares";
import { success } from "@internote/lib/responses";
import { getUserIdentityId } from "@internote/lib/user";
import { GetHandler } from "@internote/lib/types";
import { findNoteById } from "./db/queries";

const get: GetHandler<{ noteId: string }> = async (event, _ctx, callback) => {
  const { noteId } = event.pathParameters;
  const userId = getUserIdentityId(event);
  const note = await findNoteById(noteId, userId);
  return callback(null, success(note));
};

export const handler = middy(get)
  .use(encodeResponse())
  .use(httpErrorHandler())
  .use(cors());
github faultline / faultline / src / handlers / errorsGet.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new ErrorsGetHandler(aws))
        .use(httpHeaderNormalizer())
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github faultline / faultline / src / handlers / errorsList.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new ErrorsListHandler(aws))
        .use(httpHeaderNormalizer())
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github faultline / faultline / src / handlers / errorsPatch.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new ErrorsPatchHandler(aws))
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github fourTheorem / slic-starter / slic-tools / middy-util.js View on Github external
Object.keys(exports).forEach(key => {
    const handler = middy(exports[key])
      .use(
        loggerMiddleware({
          logger: log
        })
      )
      .use(httpEventNormalizer())
      .use(jsonBodyParser())
      .use(cors())
      .use(autoProxyResponse())
      .use(httpErrorHandler())

    if (options.ssmParameters && process.env.SLIC_STAGE !== 'test') {
      handler.use(
        ssm({
          cache: true,
          names: options.ssmParameters,
          awsSdkOptions: {
            endpoint: process.env.SSM_ENDPOINT_URL
          }
        })
      )
    }
    result[key] = handler
  })
  return result
github faultline / faultline / src / handlers / errorsDelete.js View on Github external
const handlerBuilder = (aws) => {
    return middy(new ErrorsDeleteHandler(aws))
        .use(checkApiKey())
        .use(httpErrorHandler())
        .use(bodyStringifier())
        .use(cors());
};
const handler = handlerBuilder(aws);
github josephluck / internote / services / preferences / get.ts View on Github external
try {
    const preferences = await findPreferencesById(getUserIdentityId(event));
    return callback(null, success(preferences));
  } catch (err) {
    if (err instanceof HttpError.NotFound) {
      const preferences = await createPreferences(getUserIdentityId(event));
      return callback(null, success(preferences));
    } else {
      throw exception(err);
    }
  }
};

export const handler = middy(get)
  .use(encodeResponse())
  .use(httpErrorHandler())
  .use(cors());