forked from ttc/micro-service-api
25 lines
901 B
JavaScript
25 lines
901 B
JavaScript
import { sendError } from '../utils/response.js'
|
|
|
|
/**
|
|
* ✅ Middleware สำหรับตรวจสอบความถูกต้องของ JSON body
|
|
* ป้องกัน body-parser crash (SyntaxError)
|
|
*/
|
|
export function validateJsonFormat(err, req, res, next) {
|
|
if (err instanceof SyntaxError && 'body' in err) {
|
|
console.error('[Invalid JSON Format]', err.message)
|
|
return sendError('รูปแบบ บอร์ดี้ ไม่ถูกต้อง', 'Invalid Body format')
|
|
}
|
|
next()
|
|
}
|
|
|
|
// /**
|
|
// * ✅ ตรวจสอบ body/query/params ว่ามีค่า organization หรือไม่
|
|
// */
|
|
// export function validateRequest(req, res, next) {
|
|
// const { organization } = req.body || {}
|
|
// if (!organization) {
|
|
// return sendResponse(res, 400, 'ไม่พบค่า organization', 'Missing organization')
|
|
// }
|
|
// next()
|
|
// }
|