Skip to content

Better Reporting of Errors on 400 Errors #279

@JasonTaylorAcronym

Description

@JasonTaylorAcronym

Currently the only message we get in the thrown exception is

Encountered a validation error (https://arl2.api.myob.com/accountright/b7259c7c-a109-4013-a6e2-9be6410ab300/Sale/Invoice/Service/?returnBody=true)

But I can see in the response body what the actual issue is

{
  "Errors": [
    {
      "Name": "CustomerNotFound",
      "Message": "The Customer with UID of '511d425d-a306-4e19-add4-de842086444a' cannot be found.",
      "AdditionalDetails": "Customer.UID",
      "ErrorCode": 11003,
      "Severity": "Error",
      "LearnMore": null
    }
  ],
  "Information": "Warning, error messages have not been finalised in this release and may change"
}

Would be much more helpful to the end user if we could display the actual error messages

I tired accessing the response stream but its been disposed already

            try
            {
                myobInvoice = _myobService.InsertInvoice(myobInvoice);
            }
            catch (Exception ex)
            {
                if (ex.InnerException is WebException)
                {
                    var webException = ex.InnerException as WebException;

                    var stream = webException.Response.GetResponseStream();

                    using (var streamReader = new StreamReader(stream)) // throws exception stream is not readable
                    {
                        var content = streamReader.ReadToEnd();
                    }
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions