Skip to content

ArgumentException when building ErrorResponse object #241

@robbiehooke

Description

@robbiehooke

The Slack chat.postMessage docs don't mention it, but when there are invalid attachments there can/will be an errors field in the response which contains an array of strings, like in the following case:

The following request:

{
  "channel": "XXXX",
  "attachments": [
    {
      "blocks": [
        {
          "image_url": "https://fastly.picsum.photos/id/825/200/300.jpg",
          "type": "image"
        }
      ]
    }
  ]
}

Returns this response:

{
    "ok": false,
    "error": "invalid_attachments",
    "errors": [
        "missing required field: alt_text [json-pointer:/attachments/0/blocks/0]"
    ],
    "response_metadata": {
        "messages": [
            "[ERROR] missing required field: alt_text [json-pointer:/attachments/0/blocks/0]"
        ]
    }
}

Reproducible message object:

new Message
{
    Channel = "XXXXX",
    Attachments = [
        new Attachment
        {
            Blocks = [
                new ImageBlock
                {
                    ImageUrl = "https://fastly.picsum.photos/id/825/200/300.jpg"
                }
            ]
        }
    ]
};

I'm not sure in what other error cases this happens, this is the first one we found.

When ErrorResponse is populated, an exception is thrown during the population of Info because the value is an array and not a string. Looks like this code was introduced recently in: 65a3d98

Happy to put up a PR, but I'm new to this library, so I'm not sure what the desired approach would be here. The content is repeated in response_metadata, so maybe errors should be excluded from being added to _info? Or a check should be made to verify the type before calling ToObject eg e.Value != JTokenType.Array?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions