Add return bool to HandleRequest to better trigger failures

This commit is contained in:
Dean Herbert
2021-03-23 18:08:32 +09:00
parent ce452565f4
commit aeff9bd853
11 changed files with 75 additions and 26 deletions

View File

@ -34,8 +34,9 @@ namespace osu.Game.Online.API
/// <summary>
/// Provide handling logic for an arbitrary API request.
/// Should return true is a request was handled. If null or false return, the request will be failed with a <see cref="NotSupportedException"/>.
/// </summary>
public Action<APIRequest> HandleRequest;
public Func<APIRequest, bool> HandleRequest;
private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
@ -55,12 +56,12 @@ namespace osu.Game.Online.API
public virtual void Queue(APIRequest request)
{
if (HandleRequest != null)
HandleRequest.Invoke(request);
else
if (HandleRequest?.Invoke(request) != true)
{
// this will fail due to not receiving an APIAccess, and trigger a failure on the request.
// this is intended - any request in testing that needs non-failures should use HandleRequest.
request.Perform(this);
}
}
public void Perform(APIRequest request) => HandleRequest?.Invoke(request);