yiisoft / validator

Yii validator library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
110 stars 36 forks source link

Return error code for API application #652

Open ghost opened 5 months ago

ghost commented 5 months ago

Return error code for property validate rules on API application.

samdark commented 5 months ago

Would you please elaborate with some example? It's not clear now.

vjik commented 5 months ago

As in symfony: https://github.com/symfony/validator/blob/bf0e20ac57f038ef6ea52f83aa474b5f567ff9a1/Constraints/Email.php#L29

Every error has individual code.

ghost commented 5 months ago

Would you please elaborate with some example? It's not clear now.

Example


errors: [
{
      "propertyPath": "email",
      "message": "Test message",
      "code": "inavalid_email"
    }
]
samdark commented 5 months ago

I see. That makes sense if client needs to handle errors of a kind in a special way.

arogachev commented 2 months ago

Need to decide where exactly the code will be attached to. Will it be a rule / individual error / similar errors (incorrect input, etc.)?

vjik commented 2 months ago

Need to decide where exactly the code will be attached to. Will it be a rule / individual error / similar errors (incorrect input, etc.)?

I think need add individual codes to individual errors. Also need ability change code as in concrete rule as in globally.