Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/do now swallow exceptions during verify #141

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Agrirouter.Api.Exception
/// Will be thrown if the onboarding process is not successful.
/// </summary>
[Serializable]
public class OnboardException : OnboardRevokeExceptionBase {
public class OnboardException : OnboardRevokeOrVerifyExceptionBase {
/// <summary>
/// Constructor.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Agrirouter.Api.Exception
/// Base exception class for errors during onboarding and revoking processes.
/// </summary>
[Serializable]
public class OnboardRevokeExceptionBase : System.Exception
public class OnboardRevokeOrVerifyExceptionBase : System.Exception
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="statusCode">-</param>
/// <param name="onboardError">-</param>
public OnboardRevokeExceptionBase(HttpStatusCode statusCode, OnboardError onboardError): base(onboardError.Message)
public OnboardRevokeOrVerifyExceptionBase(HttpStatusCode statusCode, OnboardError onboardError): base(onboardError.Message)
{
StatusCode = statusCode;
Error = onboardError;
Expand All @@ -26,7 +26,7 @@ public OnboardRevokeExceptionBase(HttpStatusCode statusCode, OnboardError onboar
/// </summary>
/// <param name="statusCode">-</param>
/// <param name="message">-</param>
public OnboardRevokeExceptionBase(HttpStatusCode statusCode, string message): base(message)
public OnboardRevokeOrVerifyExceptionBase(HttpStatusCode statusCode, string message): base(message)
{
StatusCode = statusCode;
Error = new OnboardError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Agrirouter.Api.Exception
/// Will be thrown if the revoking process is not successful.
/// </summary>
[Serializable]
public class RevokeException : OnboardRevokeExceptionBase {
public class RevokeException : OnboardRevokeOrVerifyExceptionBase {
/// <summary>
/// Constructor.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ namespace Agrirouter.Api.Exception
/// Will be thrown if the verification process is not successful.
/// </summary>
[Serializable]
public class VerificationException : System.Exception
public class VerificationException : OnboardRevokeOrVerifyExceptionBase
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="statusCode">-</param>
/// <param name="onboardError">-</param>
public VerificationException(HttpStatusCode statusCode, OnboardError onboardError) : base(statusCode,
onboardError)
{
}

/// <summary>
/// Constructor with error message only.
/// </summary>
/// <param name="statusCode">-</param>
/// <param name="message">-</param>
public VerificationException(string message) : base(message)
public VerificationException(HttpStatusCode statusCode, string message) : base(statusCode, message)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class SecuredOnboardingService
/// Constructor.
/// </summary>
/// <param name="environment">The current environment.</param>
/// <param name="utcDataService">The UTC data service.</param>
/// <param name="signatureService">The signature service.</param>
/// <param name="httpClient">The current HTTP client.</param>
public SecuredOnboardingService(Environment environment, HttpClient httpClient)
{
Expand Down Expand Up @@ -168,17 +166,8 @@ public VerificationResponse Verify(VerificationParameters verificationParameters

if (!httpResponseMessage.IsSuccessStatusCode)
{
switch (httpResponseMessage.StatusCode)
{
case HttpStatusCode.BadRequest:
throw new VerificationException(
"There was an error within the request. Please check the request parameters.");
case HttpStatusCode.Unauthorized:
throw new VerificationException("The registration code is invalid.");
default:
throw new VerificationException("The request failed, the error is unknown. The error code is " +
httpResponseMessage.StatusCode + ".");
}
var onboardErrorResponse = JsonConvert.DeserializeObject<OnboardErrorResponse>(result);
throw new OnboardException(httpResponseMessage.StatusCode, onboardErrorResponse.OnboardError);
}

var response = JsonConvert.DeserializeObject(result, typeof(VerificationResponse));
Expand Down Expand Up @@ -225,17 +214,8 @@ public async Task<VerificationResponse> VerifyAsync(VerificationParameters verif

if (!httpResponseMessage.IsSuccessStatusCode)
{
switch (httpResponseMessage.StatusCode)
{
case HttpStatusCode.BadRequest:
throw new VerificationException(
"There was an error within the request. Please check the request parameters.");
case HttpStatusCode.Unauthorized:
throw new VerificationException("The registration code is invalid.");
default:
throw new VerificationException("The request failed, the error is unknown. The error code is " +
httpResponseMessage.StatusCode + ".");
}
var onboardErrorResponse = JsonConvert.DeserializeObject<OnboardErrorResponse>(result);
throw new OnboardException(httpResponseMessage.StatusCode, onboardErrorResponse.OnboardError);
}

var response = JsonConvert.DeserializeObject<VerificationResponse>(result);
Expand Down
Loading