Refactor envelope ID retrieval and error handling
Replaced hardcoded `envelopeId` with dynamic retrieval from user claims. Reintroduced and updated error handling logic to validate the `envelopeId` and log detailed errors when parsing fails. Improved robustness by returning a 500 error for invalid or missing envelope claims.
This commit is contained in:
@@ -70,19 +70,17 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe
|
||||
[HttpGet("{envelopeKey}")]
|
||||
public async Task<IActionResult> GetDocumentOfReceiver(string envelopeKey, CancellationToken cancel)
|
||||
{
|
||||
var envelopeId = 2071;
|
||||
var envelopeIdStr = User.FindFirst(EnvelopeClaimNames.EnvelopeId)?.Value;
|
||||
|
||||
//var envelopeIdStr = User.FindFirst(EnvelopeClaimNames.EnvelopeId)?.Value;
|
||||
if (!int.TryParse(envelopeIdStr, out int envelopeId))
|
||||
{
|
||||
logger.LogError(
|
||||
"Inner service error: Failed to parse Envelope ID from claims. Claim '{ClaimName}' had an invalid or missing value: '{ClaimValue}'.",
|
||||
EnvelopeClaimNames.EnvelopeId,
|
||||
envelopeIdStr ?? "null");
|
||||
|
||||
//if (!int.TryParse(envelopeIdStr, out int envelopeId))
|
||||
//{
|
||||
// logger.LogError(
|
||||
// "Inner service error: Failed to parse Envelope ID from claims. Claim '{ClaimName}' had an invalid or missing value: '{ClaimValue}'.",
|
||||
// EnvelopeClaimNames.EnvelopeId,
|
||||
// envelopeIdStr ?? "null");
|
||||
|
||||
// return StatusCode(StatusCodes.Status500InternalServerError, "Inner service error: Invalid envelope claim.");
|
||||
//}
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Inner service error: Invalid envelope claim.");
|
||||
}
|
||||
|
||||
var senderDoc = await mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user