mirror of
https://github.com/vercel/commerce.git
synced 2025-06-30 18:31:21 +00:00
36 lines
882 B
TypeScript
36 lines
882 B
TypeScript
import type { CustomerSchema } from '../../types/customer'
|
|
import { CommerceAPIError } from '../utils/errors'
|
|
import isAllowedOperation from '../utils/is-allowed-operation'
|
|
import type { GetAPISchema } from '..'
|
|
|
|
const customerEndpoint: GetAPISchema<
|
|
any,
|
|
CustomerSchema
|
|
>['endpoint']['handler'] = async (ctx) => {
|
|
const { req, res, handlers } = ctx
|
|
|
|
if (
|
|
!isAllowedOperation(req, res, {
|
|
GET: handlers['getLoggedInCustomer'],
|
|
})
|
|
) {
|
|
return
|
|
}
|
|
|
|
try {
|
|
const body = null
|
|
return await handlers['getLoggedInCustomer']({ ...ctx, body })
|
|
} catch (error) {
|
|
console.error(error)
|
|
|
|
const message =
|
|
error instanceof CommerceAPIError
|
|
? 'An unexpected error ocurred with the Commerce API'
|
|
: 'An unexpected error ocurred'
|
|
|
|
res.status(500).json({ data: null, errors: [{ message }] })
|
|
}
|
|
}
|
|
|
|
export default customerEndpoint
|