mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-23 07:04:26 +01:00
ModelBinders should not throw exception, but return error on ModelState
This commit is contained in:
@@ -43,11 +43,17 @@ namespace BTCPayServer.ModelBinders
|
||||
var data = network.NBXplorerNetwork.DerivationStrategyFactory.Parse(key);
|
||||
if (!bindingContext.ModelType.IsInstanceOfType(data))
|
||||
{
|
||||
throw new FormatException("Invalid destination type");
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Invalid derivation scheme");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
bindingContext.Result = ModelBindingResult.Success(data);
|
||||
}
|
||||
catch { throw new FormatException("Invalid derivation scheme"); }
|
||||
catch
|
||||
{
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Invalid derivation scheme");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ namespace BTCPayServer.ModelBinders
|
||||
{
|
||||
bindingContext.Result = ModelBindingResult.Success(paymentId);
|
||||
}
|
||||
else
|
||||
{
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Invalid payment id");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ namespace BTCPayServer.ModelBinders
|
||||
{
|
||||
bindingContext.Result = ModelBindingResult.Success(walletId);
|
||||
}
|
||||
else
|
||||
{
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Invalid wallet id");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user