-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import compose from 'koa-compose' | ||
import cors from 'kcors' | ||
import { configureLambda } from '../..' | ||
import { post } from '../../../middleware/noop-route' | ||
import Errors from '../../../errors' | ||
import * as LambdaEvents from '../../lambda-events' | ||
import { fromHTTP } from '../../lambda' | ||
|
||
const lambda = fromHTTP({ | ||
event: LambdaEvents.DOCUMENT_CHECKER_WEBHOOK_EVENT, | ||
preware: compose([ | ||
post(), | ||
cors(), | ||
]) | ||
}) | ||
|
||
lambda.use(async (ctx) => { | ||
debugger | ||
const { documentChecker } = ctx.components | ||
if (!documentChecker) { | ||
throw new Errors.HttpError(404, 'not found') | ||
} | ||
|
||
const { event } = ctx | ||
try { | ||
await documentChecker.handleVerificationEvent(event) | ||
} catch (err) { | ||
lambda.logger.error('failed to handle documentChecker webhook call', err) | ||
ctx.status = 500 | ||
ctx.error = new Error('failed') | ||
} | ||
}) | ||
|
||
export const handler = lambda.handler |