You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the ValidationError constructor the typebox error result is stringified Line Reference.
I am already using SetErrorFunction provided by TypeBox and using my own messages.
Inside onError handler I cannot access the error object without parsing the error message. This applies an unnecessary overhead to application (additional parsing) as it is already an object.
Instead of stringifying the error object properties should be assigned to ValidationError instance. This will improve usability of ValidationError and there would be a slight increase in app throughput.
Example:
import{DefaultErrorFunction,SetErrorFunction,ValueErrorType}from'@sinclair/typebox/errors'import{Elysia,t}from'elysia'SetErrorFunction((err)=>{switch(err.errorType){caseValueErrorType.ObjectRequiredProperty:
return`object must contain required property "${err.path.replace('/','')}"`caseValueErrorType.String:
return'the value must be a string'default:
returnDefaultErrorFunction(err)}})newElysia().post('/validate',({body})=>body,{body: t.Object({name: t.String(),age: t.Number()}),error({code, error}){switch(code){case'VALIDATION':
returnerror.message}}}).listen(3000)
With the above code post an http request with an empty json to /validate endpoint. Because of missing property name it will return the following as a response
What version of Elysia is running?
1.1.5
In the
ValidationError
constructor the typebox error result is stringified Line Reference.I am already using SetErrorFunction provided by TypeBox and using my own messages.
Inside
onError
handler I cannot access the error object without parsing the error message. This applies an unnecessary overhead to application (additional parsing) as it is already an object.Instead of stringifying the error object properties should be assigned to
ValidationError
instance. This will improve usability ofValidationError
and there would be a slight increase in app throughput.Example:
With the above code post an http request with an empty json to
/validate
endpoint. Because of missing propertyname
it will return the following as a responseHowever I only need
"object must contain required property name"
message, so I have to parse theerror.message
and return it.EDIT: I have found that, we could use
error.all[ 0 ].message
, but still the stringification is unnecessary.The text was updated successfully, but these errors were encountered: