error records
[Joi] callStack: Error: item added into group finishDate created a dependencies error\n
알로호모라
2022. 6. 24. 15:06
반응형
Joi 를 사용하다가 나온 에러
Joi callStack: Error: item added into group finishDate created a dependencies error\n
My code :
const validationSettings = {
index: Joi.number().integer().required().label('index'),
startDate: Joi.date()
.format('YYYY-MM-DD')
.min(
Joi.ref('finishDate', {
adjust: finishDate => new Date(finishDate.setDate(finishDate.getDate() - 89)),
}),
)
.label('startDate'),
finishDate: Joi.date().format('YYYY-MM-DD').max(Joi.ref('startDate')).label('finishDate'),
};
Error:
{
"error": {
"status": 500,
"name": "Error",
"message": "item added into group finishDate created a dependencies error"
}
}
Joi.ref() 를 사용할 때 A->B, B->A이렇게 순환 구조로 서로를 바라보게 하면 위와 같은 에러가 난다고 한다. 둘 중 하나를 다른 매서드로 대체해야한다. Joi.Ref -> max('now')로 변경하니 해결되었다.
The reason was because I used Joi.ref('fihishDate') in startDate and Joi.ref('startDate') in finishDate. You can't create a circular dependency. You need to use object assert.
I used max('now') instead of Joi.ref()
finishDate: Joi.date().format('YYYY-MM-DD').max('now').label('finishDate'),
And now it works !@
Reference : https://github.com/sideway/joi/issues/2461
반응형