feat: 后端初始化
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import type { Context } from '@netlify/functions'
|
||||
import { fail } from './http.js'
|
||||
|
||||
export type FunctionHandler = (request: Request, context: Context) => Promise<Response> | Response
|
||||
|
||||
export const withErrorBoundary = (handler: FunctionHandler): FunctionHandler => {
|
||||
return async (request, context) => {
|
||||
try {
|
||||
return await handler(request, context)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return fail('Internal server error', 500, 'INTERNAL_SERVER_ERROR')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user