Normalize greenfield responses for 404s (#3220)

This commit is contained in:
Andrew Camilleri
2021-12-23 05:32:08 +01:00
committed by GitHub
parent ae33fc3031
commit 5f5f71bf37
10 changed files with 49 additions and 70 deletions

View File

@@ -42,14 +42,14 @@ namespace BTCPayServer.Controllers.GreenField
[Authorize(Policy = Policies.CanViewPaymentRequests, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpGet("~/api/v1/stores/{storeId}/payment-requests/{paymentRequestId}")]
public async Task<ActionResult<Client.Models.PaymentRequestData>> GetPaymentRequest(string storeId, string paymentRequestId)
public async Task<IActionResult> GetPaymentRequest(string storeId, string paymentRequestId)
{
var pr = await _paymentRequestRepository.FindPaymentRequests(
new PaymentRequestQuery() { StoreId = storeId, Ids = new[] { paymentRequestId } });
if (pr.Total == 0)
{
return NotFound();
return PaymentRequestNotFound();
}
return Ok(FromModel(pr.Items.First()));
@@ -58,13 +58,13 @@ namespace BTCPayServer.Controllers.GreenField
[Authorize(Policy = Policies.CanModifyPaymentRequests,
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpDelete("~/api/v1/stores/{storeId}/payment-requests/{paymentRequestId}")]
public async Task<ActionResult> ArchivePaymentRequest(string storeId, string paymentRequestId)
public async Task<IActionResult> ArchivePaymentRequest(string storeId, string paymentRequestId)
{
var pr = await _paymentRequestRepository.FindPaymentRequests(
new PaymentRequestQuery() { StoreId = storeId, Ids = new[] { paymentRequestId }, IncludeArchived = false });
if (pr.Total == 0)
{
return NotFound();
return PaymentRequestNotFound();
}
var updatedPr = pr.Items.First();
@@ -112,7 +112,7 @@ namespace BTCPayServer.Controllers.GreenField
new PaymentRequestQuery() { StoreId = storeId, Ids = new[] { paymentRequestId } });
if (pr.Total == 0)
{
return NotFound();
return PaymentRequestNotFound();
}
var updatedPr = pr.Items.First();
@@ -164,5 +164,10 @@ namespace BTCPayServer.Controllers.GreenField
CustomCSSLink = blob.CustomCSSLink
};
}
private IActionResult PaymentRequestNotFound()
{
return this.CreateAPIError(404, "payment-request-not-found", "The payment request was not found");
}
}
}