-
Notifications
You must be signed in to change notification settings - Fork 15
Error Handling and Responses
Arun Prakash edited this page Dec 1, 2025
·
3 revisions
All operations return WordpressResponse<T> which is either:
-
WordpressSuccessResponse<T>withdata,code,message,headers,duration -
WordpressFailureResponsewitherror,code,headers,duration
final resp = await client.posts.list(ListPostRequest(perPage: 10));
// 1) Pattern matching
switch (resp) {
case WordpressSuccessResponse():
print(resp.data);
case WordpressFailureResponse():
print(resp.error);
}
// 2) map
final items = resp.map(
onSuccess: (s) => s.data,
onFailure: (_) => <Post>[],
);
// 3) Throw on failure
final posts = (await client.posts.list(ListPostRequest(perPage: 10))).dataOrThrow();
// 4) Access timings/headers
final ms = resp.duration.inMilliseconds;
final code = resp.code;If you need untyped responses for storage or custom parsing, use the raw APIs.
final raw = await client.raw(
WordpressRequest(
method: HttpMethod.get,
url: RequestUrl.relative('posts'),
),
);
print(raw.code);
print(raw.data); // bytes / string / jsonTip: Combine with the Caching middleware for efficient repeated GETs.
- π Welcome to our Wiki!
- π Usage
- π Using Custom Requests
- π‘ Authorization
- π Supported REST Methods
- π API Changelog
- π Middlewares
- π« Parallel Requests
- π§© Interfaces & Extensions
- π‘οΈ Error Handling & Responses
- βοΈ Bootstrap & Configuration
- π Events & Statistics
- π Pagination & Finders