@@ -3036,7 +3036,7 @@ proc decodeBody*(
30363036 [version, $ exc.msg]))
30373037 ok (RestPublishedSignedBeaconBlock (ForkedSignedBeaconBlock .init (blck)))
30383038 else :
3039- err (RestErrorMessage .init (Http415 , " Invalid content type " ,
3039+ err (RestErrorMessage .init (Http415 , InvalidContentTypeError ,
30403040 [version, $ body.contentType]))
30413041
30423042proc decodeBody * (
@@ -3232,9 +3232,45 @@ proc decodeBody*(
32323232 ok (RestPublishedSignedBlockContents (
32333233 kind: ConsensusFork .Fulu , fuluData: blckContents))
32343234 else :
3235- err (RestErrorMessage .init (Http415 , " Invalid content type " ,
3235+ err (RestErrorMessage .init (Http415 , InvalidContentTypeError ,
32363236 [version, $ body.contentType]))
32373237
3238+ proc decodeBodyJsonOrSsz * (
3239+ t: typedesc [seq [SignedValidatorRegistrationV1 ]],
3240+ body: ContentBody
3241+ ): Result [seq [SignedValidatorRegistrationV1 ], RestErrorMessage ] =
3242+ if body.contentType == ApplicationJsonMediaType :
3243+ let data =
3244+ try :
3245+ RestJson .decode (
3246+ body.data,
3247+ seq [SignedValidatorRegistrationV1 ],
3248+ requireAllFields = true ,
3249+ allowUnknownFields = true )
3250+ except SerializationError as exc:
3251+ debug " Failed to deserialize REST JSON data" ,
3252+ err = exc.formatMsg (" <data>" )
3253+ return err (
3254+ RestErrorMessage .init (Http400 , UnableDecodeError ,
3255+ [exc.formatMsg (" <data>" )]))
3256+ ok (data)
3257+ elif body.contentType == OctetStreamMediaType :
3258+ let data =
3259+ try :
3260+ SSZ .decode (
3261+ body.data,
3262+ List [SignedValidatorRegistrationV1 , Limit VALIDATOR_REGISTRY_LIMIT ])
3263+ except SerializationError as exc:
3264+ debug " Failed to deserialize REST SSZ data" ,
3265+ err = exc.formatMsg (" <data>" )
3266+ return err (
3267+ RestErrorMessage .init (Http400 , UnableDecodeError ,
3268+ [exc.formatMsg (" <data>" )]))
3269+ ok (data.toSeq)
3270+ else :
3271+ err (RestErrorMessage .init (Http415 , InvalidContentTypeError ,
3272+ [$ body.contentType]))
3273+
32383274proc decodeBody * [T](t: typedesc [T],
32393275 body: ContentBody ): Result [T, cstring ] =
32403276 if body.contentType != ApplicationJsonMediaType :
@@ -3285,7 +3321,7 @@ proc decodeBodyJsonOrSsz*[T](t: typedesc[T],
32853321 RestErrorMessage .init (Http400 , UnexpectedDecodeError , [$ exc.msg]))
32863322 ok (blck)
32873323 else :
3288- err (RestErrorMessage .init (Http415 , " Invalid content type " ,
3324+ err (RestErrorMessage .init (Http415 , InvalidContentTypeError ,
32893325 [$ body.contentType]))
32903326
32913327proc encodeBytes * [T: EncodeTypes ](value: T,
0 commit comments