Skip to content

Conversation

@Dreamescaper
Copy link
Contributor

@Dreamescaper Dreamescaper commented Apr 11, 2020

What kind of change does this PR introduce?
fixes #844, fixes #882, fixes #272, fixes #562

What is the current behavior?
Refit throws exception if response status is not successful. No (easy) way to override that behavior.

What is the new behavior?
Add property to RefitSettings:
public Func<HttpResponseMessage, Task<Exception>> ExceptionFactory { get; set; }

Throw exception created by this Func. If it returns null - do not throw anything.

Also, added overload to ApiException.Create method to allow to provide custom exception message.

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

Open question: I wanted to allow to create custom exceptions (i.e. non ApiException), however that leads to issue when Api method returns ApiResponse. It has property ApiException Error { get; }, and I cannot put custom Exception type there. Currently I simply ignore exception, if it is not ApiException.
Not sure whether there is a better way.

@Dreamescaper Dreamescaper mentioned this pull request May 19, 2020
2 tasks
@clairernovotny
Copy link
Member

Sorry for taking so long to get to this. If you can please rebase this, I'll get it merged.

@Dreamescaper
Copy link
Contributor Author

@clairernovotny
Rebased.

@clairernovotny clairernovotny merged commit 2e94493 into reactiveui:master Sep 5, 2020
@Dreamescaper Dreamescaper deleted the customize_exceptions branch September 5, 2020 23:01
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

2 participants