StashApiCSharp
StashApiCSharp copied to clipboard
Improve handling of errors returned by bitbucket.
When creating a pull request via PullRequests.Create if the specified from branch / to branch is not found, bitbucket will return 404 not found. But the contents of the response will be a JSON structure that explains what was not found.
The issue is this JSON response is never read if the HTTP status code is 404.
The exception thrown is: POST operation unsuccessful. Got HTTP status code 404.
I have modified a local checkout of the code to add reading the response data, which provides me the JSON error details as text in the exception:
Modified code - HttpCommunicationWorker, Line 97:
string error = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new Exception(string.Format("POST operation unsuccessful. Got HTTP status code '{0}' \nContent:\n{1}", httpResponse.StatusCode, error));
This is not ideal as it would be nice to deserialize the JSON error response to some sort of class structure.
Thanks.