-first commit
This commit is contained in:
24
exthernal-mobile-api/src/middlewares/validate.js
Normal file
24
exthernal-mobile-api/src/middlewares/validate.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { sendResponse } 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 sendResponse(res, 400, 'รูปแบบ บอร์ดี้ ไม่ถูกต้อง', '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()
|
||||
// }
|
||||
Reference in New Issue
Block a user