-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#372: Move error parsing from MollieApiException to BaseMollieClient
- Loading branch information
1 parent
183ec7a
commit 8831e1b
Showing
2 changed files
with
19 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,12 @@ | ||
using System; | ||
using System.Net; | ||
using Mollie.Api.Models.Error; | ||
using Newtonsoft.Json; | ||
|
||
namespace Mollie.Api.Client { | ||
public class MollieApiException : Exception { | ||
public MollieErrorMessage Details { get; set; } | ||
|
||
public MollieApiException(HttpStatusCode httpStatusCode, string responseBody) | ||
: base(ParseErrorMessage(httpStatusCode, responseBody).ToString()){ | ||
Details = ParseErrorMessage(httpStatusCode, responseBody); | ||
} | ||
|
||
private static MollieErrorMessage ParseErrorMessage(HttpStatusCode httpStatusCode, string responseBody) { | ||
try { | ||
return JsonConvert.DeserializeObject<MollieErrorMessage>(responseBody)!; | ||
} | ||
catch (JsonReaderException) { | ||
return new MollieErrorMessage { | ||
Title = "Unknown error", | ||
Status = (int)httpStatusCode, | ||
Detail = responseBody | ||
}; | ||
} | ||
public MollieApiException(MollieErrorMessage details) : base(details.ToString()) { | ||
Details = details; | ||
} | ||
} | ||
} |