tzmfreedom / rustforce

Salesforce REST API Client by Rust
MIT License
41 stars 19 forks source link

Why Vec<ErrorResponse> instead of plain ErrorResponse? #3

Closed fusillicode closed 4 years ago

fusillicode commented 4 years ago

Hi 😄

First of all thanks really a lot for tall your work on this crate 🙇 .

Sorry for opening this issue but I'm trying to understand the reason behind the usage of Vec<ErrorResponse> inside the Client queries methods.

I tried to skim around the code but I wasn't able to figure out the when you're getting a Vec instead of a bare reqwest error and consequently a rustforce ErrorResponse.

The reason why I'm trying to understand it is because I'm getting some difficulties in handling the type Vec<ErrorResponse> instead of a "bare bones" ErrorResponse and I'm wondering if I just can safely assume that, in case of an Err, I can find it as the first element of the returned Vec<ErrorResponse>.

I hope that my doubts and the the issue I'm facing is clear. If that's not the case please do not hesitate to ask some clarification.

Thanks again!

tzmfreedom commented 4 years ago

@fusillicode Thank you for opening issue !

The reason is that error response from salesforce is error object array, not object. For example, if we put no exist field to query request, we get the following error.

[ {
  "message" : "\nSelect foo FROM Account\n       ^\nERROR at Row:1:Column:8\nNo such column 'foo' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
  "errorCode" : "INVALID_FIELD"
} ]

So I parse it as array that is identical to error response format, however it may be almost single element array.

fusillicode commented 4 years ago

@tzmfreedom thank you for the quick and exhaustive reply!

Everything is clear now! I was missing the unwrap() inside the methods and so I was getting confused between the handling of the reqwest errors and the actual SF errors!

Thanks again for all your work and for you invaluable support! 🙇

Cheers!