Automattic / Automattic/wordpress-rs

Support converting unhandled errors to specific types

Open
#788 2 comments 0 reactions 1 assignee Claimed by @oguzkocer View on GitHub
Dominant language
Rust
Stars
36
Forks
5
Avg merge
17h 30m
Merged PRs (30d)
43

Description

We have been able to convert all error types to `WpApiError` for WordPress REST API endpoints. However, if a site returns a custom error, we can't parse it and will return it as `WpApiError::Unknown`. The client can further parse the response using the `WpApiError::Unknown::response` field, but we can add some helpers to parse them to some known types.

We also probably don't need both `WpApiError::ResponseParsingError` & `WpApiError::UnknownError`, what do you think @crazytonyli?

---

One alternative we could consider is to allow each endpoint to return its own error type. I think this would work very well if this was a standalone Rust project, because we could use generics and trait bounds to still have some central handling. However, it may prove difficult for a `uniffi` project, because we are not allowed to use generics in the bindings and we can't return a trait bound object if I remember correctly.

Another alternative would be to add some WordPress.com specific error types, but that won't be a generic solution that'd allow working with custom plugins in the future.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.