pub enum ResourceError {
NotFound {
resource: &'static str,
id: String,
},
ValidationFailed {
errors: HashMap<String, Vec<String>>,
request_id: Option<String>,
},
PathResolutionFailed {
resource: &'static str,
operation: &'static str,
},
Http(HttpError),
Rest(RestError),
}Expand description
Error type for REST resource operations.
This enum provides semantic error types for resource operations, mapping HTTP error codes to meaningful variants while preserving the request ID for debugging.
§Example
use shopify_sdk::rest::ResourceError;
use std::collections::HashMap;
// Not found error
let error = ResourceError::NotFound {
resource: "Product",
id: "123".to_string(),
};
assert!(error.to_string().contains("Product"));
assert!(error.to_string().contains("123"));
// Validation failed error
let mut errors = HashMap::new();
errors.insert("title".to_string(), vec!["can't be blank".to_string()]);
let error = ResourceError::ValidationFailed {
errors,
request_id: Some("abc-123".to_string()),
};
assert!(error.to_string().contains("Validation failed"));Variants§
NotFound
The resource was not found (HTTP 404).
This error is returned when attempting to find, update, or delete a resource that doesn’t exist.
Fields
ValidationFailed
Validation failed for the resource (HTTP 422).
This error is returned when the API rejects a create or update request due to validation errors.
Fields
PathResolutionFailed
No valid path matches the provided IDs and operation.
This error is returned when attempting an operation without providing the required parent resource IDs.
Fields
Http(HttpError)
An HTTP-level error occurred.
This variant wraps HttpError for errors that don’t map to
a specific resource error type.
Rest(RestError)
A REST-level error occurred.
This variant wraps RestError for REST client errors.
Implementations§
Source§impl ResourceError
impl ResourceError
Sourcepub fn from_http_response(
code: u16,
body: &Value,
resource: &'static str,
id: Option<&str>,
request_id: Option<&str>,
) -> Self
pub fn from_http_response( code: u16, body: &Value, resource: &'static str, id: Option<&str>, request_id: Option<&str>, ) -> Self
Creates a ResourceError from an HTTP response status code.
Maps HTTP status codes to semantic error variants:
- 404 ->
NotFound - 422 ->
ValidationFailed(parsing errors from body) - Other ->
Http
§Arguments
code- The HTTP status codebody- The response body as JSONresource- The resource type name (e.g., “Product”)id- The resource ID (if applicable)request_id- The X-Request-Id header value
§Example
use shopify_sdk::rest::ResourceError;
use serde_json::json;
let error = ResourceError::from_http_response(
404,
&json!({"error": "Not found"}),
"Product",
Some("123"),
Some("req-123"),
);
assert!(matches!(error, ResourceError::NotFound { .. }));Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Returns the request ID if available.
Useful for debugging and error reporting.