Crates.io | rp-postgrest-error |
lib.rs | rp-postgrest-error |
version | |
source | src |
created_at | 2024-10-26 09:23:22.345029 |
updated_at | 2024-11-24 21:00:57.469009 |
description | strongly typed errors for PostgREST |
homepage | https://github.com/roberts-pumpurs/supabase-rs-utils |
repository | https://github.com/roberts-pumpurs/supabase-rs-utils |
max_upload_size | |
id | 1423676 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A Rust crate for parsing and handling error responses from PostgREST and PostgreSQL, providing structured error types and utility functions.
Add the following to your Cargo.toml:
[dependencies]
rp-postgrest-error = "0.1.0"
Replace "0.1.0" with the latest version of the crate.
Parsing Error Responses
The crate provides an Error enum that represents different types of errors that can occur when interacting with PostgREST:
To parse an error response from PostgREST, you can use the from_error_response method:
use rp_postgrest_error::{Error, ErrorResponse};
// Example error response from PostgREST
let error_response = ErrorResponse {
message: "duplicate key value violates unique constraint".to_owned(),
code: "23505".to_owned(),
details: Some("Key (id)=(1) already exists.".to_owned()),
hint: None,
};
// Parse the error response
let error = Error::from_error_response(error_response);
match error {
Error::PostgresError(pg_error) => {
println!("PostgreSQL Error: {}", pg_error.message);
}
Error::PostgrestError(pgrst_error) => {
println!("PostgREST Error: {}", pgrst_error.message);
}
Error::CustomError(custom_error) => {
println!("Custom Error: {}", custom_error.message);
}
}