Skip to content

Commit 60e18a5

Browse files
author
Kevin Hellemun
committed
Refactored exception factory to use the response id. (#63)
1 parent 03912ab commit 60e18a5

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

BunqSdk/Exception/ExceptionFactory.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,49 @@ public class ExceptionFactory
1818
/// <summary>
1919
/// Glue to concatenate the error messages.
2020
/// </summary>
21-
private const string GLUE_ERROR_MESSAGES = "\n";
21+
private const string SEPARATOR_ERROR_MESSAGES = "\n";
22+
23+
/// <summary>
24+
/// String format constants.
25+
/// </summary>
26+
private static string FORMAT_ERROR_MESSAGE = "Response id to help bunq debug: {0}. \n Error message: {1.}";
2227

2328
/// <returns>The exception that belongs to this status code.</returns>
24-
public static ApiException CreateExceptionForResponse(int responseCode, IList<string> messages)
29+
public static ApiException CreateExceptionForResponse(
30+
int responseCode,
31+
IList<string> messages,
32+
string responseId
33+
)
2534
{
26-
var errorMessage = ConcatenateMessages(messages);
35+
var errorMessage = ConcatenateAllMessage(messages, responseId);
2736

2837
switch (responseCode)
2938
{
3039
case HTTP_RESPONSE_CODE_BAD_REQUEST:
31-
return new BadRequestException(responseCode, errorMessage);
40+
return new BadRequestException(responseCode, errorMessage, responseId);
3241
case HTTP_RESPONSE_CODE_UNAUTHORIZED:
33-
return new UnauthorizedException(responseCode, errorMessage);
42+
return new UnauthorizedException(responseCode, errorMessage, responseId);
3443
case HTTP_RESPONSE_CODE_FORBIDDEN:
35-
return new ForbiddenException(responseCode, errorMessage);
44+
return new ForbiddenException(responseCode, errorMessage, responseId);
3645
case HTTP_RESPONSE_CODE_NOT_FOUND:
37-
return new NotFoundException(responseCode, errorMessage);
46+
return new NotFoundException(responseCode, errorMessage, responseId);
3847
case HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED:
39-
return new MethodNotAllowedException(responseCode, errorMessage);
48+
return new MethodNotAllowedException(responseCode, errorMessage, responseId);
4049
case HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS:
41-
return new TooManyRequestsException(responseCode, errorMessage);
50+
return new TooManyRequestsException(responseCode, errorMessage, responseId);
4251
case HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR:
43-
return new PleaseContactBunqException(responseCode, errorMessage);
52+
return new PleaseContactBunqException(responseCode, errorMessage, responseId);
4453
default:
45-
return new UnknownApiErrorException(responseCode, errorMessage);
54+
return new UnknownApiErrorException(responseCode, errorMessage, responseId);
4655
}
4756
}
4857

49-
private static string ConcatenateMessages(IEnumerable<string> messages)
58+
private static string ConcatenateAllMessage(IEnumerable<string> messages, string responseId)
5059
{
51-
return string.Join(GLUE_ERROR_MESSAGES, messages);
60+
return string.Format(FORMAT_ERROR_MESSAGE,
61+
responseId,
62+
string.Join(SEPARATOR_ERROR_MESSAGES, messages)
63+
);
5264
}
5365
}
5466
}

0 commit comments

Comments
 (0)