Skip to content

Add missing fields to InvalidInputError type #247

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
melih154 opened this issue Apr 14, 2022 · 2 comments
Closed

Add missing fields to InvalidInputError type #247

melih154 opened this issue Apr 14, 2022 · 2 comments

Comments

@melih154
Copy link

melih154 commented Apr 14, 2022

Thanks for this great library, helps a lot.

Can you please add itemIdentification, resourceId and resourceIdentifier fields to InvalidInputError type? Errors only contains code and message, where as Commercetools API includes itemIdentification, resourceId and resourceIdentifier fields on errors section.

Trying to implement an API that returns a validation error message type (not message) on API response. You can test it on add line item to my cart by setting line item sku as an invalid one.

CT API Response

{
    "statusCode": 400,
    "message": "LineItem error: No published product with an sku 'invalidSKU' exists.",
    "errors": [
        {
            "code": "InvalidInput",
            "message": "LineItem error: No published product with an sku 'invalidSKU' exists.",
            "itemIdentification": {
                "sku": "invalidSKU",
                "type": "LineItemSkuIdentification"
            },
            "resourceId": "xxxxx",
            "resourceIdentifier": "cart"
        }
    ]
}

CT TS SDK Response
[{"code":"InvalidInput","message":"No published product with an sku 'invalidSKU' exists."}]

@ajimae
Copy link
Contributor

ajimae commented Apr 15, 2022

Hi @melih154

Thanks for reporting this, we will look at it and see how we can go about implementing it.

Regards

@jenschude
Copy link
Contributor

The issue comes from the fact that the InvalidInput error is a quite generic one. And according to the docs no additional fields are specified. And as we don't have a formal specification of the fields we can't rely on them being in the response and implement them in the SDKs.

You should be able to access any key of the InvalidInputError but you will not get back a type safe object:

export interface InvalidInputError {
readonly code: 'InvalidInput'
[key: string]: any
/**
*
*/
readonly message: string
}

@ajimae ajimae closed this as completed Jun 22, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants