Skip to content

Add support for custom cancellation error#683

Merged
Lukasa merged 1 commit into
swift-server:mainfrom
dnadoba:dn-custom-request-cancel-error
Apr 13, 2023
Merged

Add support for custom cancellation error#683
Lukasa merged 1 commit into
swift-server:mainfrom
dnadoba:dn-custom-request-cancel-error

Conversation

@dnadoba

@dnadoba dnadoba commented Apr 13, 2023

Copy link
Copy Markdown
Collaborator

Motivation

A users might want to provide more information why a request got cancelled. For example if we cancel a file download because the response status code is not 2xx, it is desirable to propagate which status code was returned.

Modification

  • add Task.fail(_:) in addition to Task.cancel() that takes a custom Error which is used to complete the underlying request promise.

Result

Improved error messages.

@dnadoba dnadoba added the 🆕 semver/minor Adds new public API. label Apr 13, 2023

@MaxDesiatov MaxDesiatov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splendid, thank you!

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice change, I like this a lot.

@Lukasa Lukasa merged commit b9029ef into swift-server:main Apr 13, 2023
@dnadoba dnadoba deleted the dn-custom-request-cancel-error branch April 13, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants