Skip to content

Result type fails to map when 'WhenError()' is used before 'WhenSuccess()' #5

@maximegelinas-sherweb

Description

@maximegelinas-sherweb

The following code throw the following exception:

await (await this._userManagementService.GetUserInfo())
                .WhenError()
                .MapTo(
                    statusCode => Task.FromResult(
                        new HttpResponseMessage
                        {
                            StatusCode = statusCode
                        }))
                .WhenSuccess()
                .MapTo(
                    async email => await this.Post("tenant/setup", tenantId, new[] { email }))
                .Map();
System.InvalidCastException: Unable to cast object of type 'SolidStack.Core.Flow.Internal.Result.UnresolvedMappableError`3[System.Net.HttpStatusCode,Smo365Api.Services.Dtos.User.UserInfo,System.Threading.Tasks.Task`1[System.Net.Http.HttpResponseMessage]]' to type 'SolidStack.Core.Flow.Internal.Result.ResolvedMappableSuccess`3[System.Net.HttpStatusCode,Smo365Api.Services.Dtos.User.UserInfo,System.Threading.Tasks.Task`1[System.Net.Http.HttpResponseMessage]]'.\r\n   at SolidStack.Core.Flow.Internal.MappableContent`3.TryUseLastMapping()\r\n   at SolidStack.Core.Flow.Internal.Result.UnresolvedMappableError`3.WhenSuccess()\r\n

But this code don't:

await (await this._userManagementService.GetUserInfo())
                .WhenSuccess()
                .MapTo(
                    async email => await this.Post("tenant/setup", tenantId, new[] { email }))
                .WhenError()
                .MapTo(
                    statusCode => Task.FromResult(
                        new HttpResponseMessage
                        {
                            StatusCode = statusCode
                        }))
                .Map();

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions