#[non_exhaustive]pub enum MyIdError {
Config {
message: String,
},
Validation {
message: String,
},
Http(Error),
Api {
status: u16,
message: String,
},
Internal {
message: String,
},
}Expand description
MyID SDK ning asosiy xatolik tipi.
Barcha SDK operatsiyalari xato bo’lganda shu enum qaytariladi. Har bir variant alohida xato kategoriyasini ifodalaydi.
§Misollar
use myid::error::MyIdError;
// Config xatosi
let err = MyIdError::config("noto'g'ri URL formati");
println!("{err}"); // "config error: noto'g'ri URL formati"
// API xatosi
let err = MyIdError::api(401, "unauthorized");
println!("{err}"); // "api error 401: unauthorized"Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Config
Konfiguratsiya xatosi.
Config::new(),
Config::from_env(), yoki
with_*() metodlarida validatsiya muvaffaqiyatsiz bo’lganda qaytariladi.
§Misol
use myid::config::Config;
use myid::error::MyIdError;
let err = Config::new("ftp://example.uz", "id", "secret").unwrap_err();
assert!(matches!(err, MyIdError::Config { .. }));Validation
Ma’lumotlarni validatsiya xatosi.
So’rov parametrlari noto’g’ri yoki yetishmagan bo’lganda qaytariladi. Masalan: majburiy field bo’sh, format noto’g’ri, qiymat chegaradan tashqarida.
§Qachon yuz beradi
| Sabab | Misol |
|---|---|
| Majburiy field bo’sh | photo berilmagan |
| Format noto’g’ri | birth_date noto’g’ri format |
| Qiymat chegaradan tashqari | passport_series 2 belgidan kam |
§Misol
use myid::error::MyIdError;
let err = MyIdError::validation("photo maydoni majburiy");
assert!(matches!(err, MyIdError::Validation { .. }));
println!("{err}"); // "validation error: photo maydoni majburiy"Http(Error)
HTTP transport xatosi.
reqwest kutubxonasi qaytargan xatolar avtomatik convert bo’ladi.
Timeout, DNS resolution, TLS handshake, connection refused va
boshqa tarmoq xatoliklari shu variantga tushadi.
§Qachon yuz beradi
- Server javob bermasa (timeout)
- DNS nomi topilmasa
- TLS sertifikat xatosi
- Connection refused
- Response body parse bo’lmasa
Api
API javobidagi xato (4xx/5xx status kodlari).
MyID serveri so’rovni qabul qildi, lekin xato javob qaytardi.
status — HTTP status kodi, message — server javobi.
§Tez-tez uchraydigan kodlar
| Status | Sababi |
|---|---|
| 400 | Noto’g’ri so’rov parametrlari |
| 401 | client_id yoki client_secret noto’g’ri |
| 403 | Ruxsat berilmagan |
| 429 | Rate limit — juda ko’p so’rov |
| 500 | Server ichki xatosi |
Fields
Internal
SDK ichki xatosi.
Odatiy foydalanishda yuz bermasligi kerak. Mutex lock poisoning yoki boshqa kutilmagan holatlar uchun.
Implementations§
Source§impl MyIdError
impl MyIdError
Sourcepub fn config(message: impl Into<String>) -> Self
pub fn config(message: impl Into<String>) -> Self
MyIdError::Config variantini yaratadi.
§Misollar
use myid::error::MyIdError;
let err = MyIdError::config("noto'g'ri URL");
let err = MyIdError::config(format!("yo'q: {}", "MYID_BASE_URL"));Sourcepub fn validation(message: impl Into<String>) -> Self
pub fn validation(message: impl Into<String>) -> Self
MyIdError::Validation variantini yaratadi.
use myid::error::MyIdError;
let err = MyIdError::validation("passport_series majburiy");Sourcepub fn http(source: Error) -> Self
pub fn http(source: Error) -> Self
MyIdError::Http variantini reqwest::Error dan yaratadi.
Odatda ? operatori orqali avtomatik convert bo’ladi (#[from]).
Bu metod faqat qo’shimcha kontekst kerak bo’lganda ishlatiladi.
Sourcepub fn api(status: u16, message: impl Into<String>) -> Self
pub fn api(status: u16, message: impl Into<String>) -> Self
MyIdError::Api variantini yaratadi.
§Misollar
use myid::error::MyIdError;
let err = MyIdError::api(401, "unauthorized");
let err = MyIdError::api(500, "internal server error");Sourcepub fn is_api(&self) -> bool
pub fn is_api(&self) -> bool
Xato API xatosimi yoki yo’qligini tekshiradi.
use myid::error::MyIdError;
let err = MyIdError::api(401, "unauthorized");
assert!(err.is_api());Sourcepub fn api_status(&self) -> Option<u16>
pub fn api_status(&self) -> Option<u16>
API xato bo’lsa status kodini qaytaradi.
use myid::error::MyIdError;
let err = MyIdError::api(429, "rate limited");
assert_eq!(err.api_status(), Some(429));Trait Implementations§
Source§impl Error for MyIdError
impl Error for MyIdError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Auto Trait Implementations§
impl Freeze for MyIdError
impl !RefUnwindSafe for MyIdError
impl Send for MyIdError
impl Sync for MyIdError
impl Unpin for MyIdError
impl UnsafeUnpin for MyIdError
impl !UnwindSafe for MyIdError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.