openwallet-foundation / credo-ts-ext

Extension libraries for Credo
https://credo.js.org
Apache License 2.0
29 stars 37 forks source link

[rest] Error handling and validation #125

Open berendsliedrecht opened 2 years ago

berendsliedrecht commented 2 years ago

Ive had some issues with the errors that are being returned from the api. For example, I think I forgot a field in the credentials/offer-credential endpoint and this was the response:

[error] Internal Server Error (status code: 500)! Message: {"stack":"TypeError: Cannot read properties of undefined (reading 'startsWith')\n    at Object.replaceLegacyDidSovPrefix (/www/node_modules/@aries-framework/core/build/utils/messageType.js:15:21)\n    at Object.class_transformer_1.Transform.toClassOnly [as transformFn] (/www/node_modules/@aries-framework/core/build/modules/credentials/messages/CredentialPreview.js:86:64)\n    at /www/node_modules/class-transformer/cjs/TransformOperationExecutor.js:358:30\n    at Array.forEach (<anonymous>)\n    at TransformOperationExecutor.applyCustomTransformations (/www/node_modules/class-transformer/cjs/TransformOperationExecutor.js:357:19)\n    at TransformOperationExecutor.transform (/www/node_modules/class-transformer/cjs/TransformOperationExecutor.js:300:47)\n    at TransformOperationExecutor.transform (/www/node_modules/class-transformer/cjs/TransformOperationExecutor.js:299:47)\n    at ClassTransformer.plainToInstance (/www/node_modules/class-transformer/cjs/ClassTransformer.js:27:25)\n    at Object.plainToClass (/www/node_modules/class-transformer/cjs/index.js:34:29)\n    at ActionParameterHandler.transformValue (/www/node_modules/routing-controllers/cjs/ActionParameterHandler.js:189:41)","message":"Cannot read properties of undefined (reading 'startsWith')"}

I believe if we only send the message field, Cannot read properties of undefined (reading 'startsWith') back it will already be a lot better. But this error also goes into my second point, startsWith is being called on undefined, so apparently I forgot a value in my call but I have no idea which one.

Some stricter validation with better error messages would be insanely benificial.

berendsliedrecht commented 2 years ago

My request body for this error (in Rust debug prints was this):

[trace] Some(
    Object({
        "attachments": String(
            "string",
        ),
        "comment": String(
            "string",
        ),
        "connectionId": String(
            "foo",
        ),
        "credentialDefinitionId": String(
            "bar",
        ),
        "preview": Object({
            "attributes": Array([
                String(
                    "string",
                ),
            ]),
            "type": String(
                "https://didcomm.org/issue-credential/1.0/credential-preview",
            ),
        }),
    }),
)
TimoGlastra commented 2 years ago

Will this be fixed by #148?