mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 09:48:44 +00:00
invalid api key
This commit is contained in:
1 parent
dd973a2378
commit
bdf3170648
2 files changed
+7
-5
No files matched your search
@@ -1,8 +1,8 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::webhook_api::payload::webhook_inner_payload::{WebhookInnerPayload, SuccessData, ErrorData, PayloadErrorData};
|
||||
use crate::webhook_api::payload::webhook_payload::{WebhookPayload, WebhookStatus};
|
||||
use crate::webhook_api::payload::webhook_error_type::WebhookErrorType;
|
||||
use crate::webhook_api::payload::webhook_inner_payload::{ErrorData, PayloadErrorData, SuccessData, WebhookInnerPayload};
|
||||
use crate::webhook_api::payload::webhook_payload::{WebhookPayload, WebhookStatus};
|
||||
|
||||
/// Parse the inner payload of a FAL webhook into one of three cases.
|
||||
///
|
||||
@@ -12,7 +12,7 @@ use crate::webhook_api::payload::webhook_error_type::WebhookErrorType;
|
||||
pub fn parse_webhook_inner_payload(webhook: &WebhookPayload) -> WebhookInnerPayload {
|
||||
match webhook.status {
|
||||
WebhookStatus::Error => {
|
||||
let (message, error_type) = extract_first_detail(&webhook.payload);
|
||||
let (message, error_type) = extract_error_first_detail(&webhook.payload);
|
||||
|
||||
WebhookInnerPayload::Error(ErrorData {
|
||||
message,
|
||||
@@ -37,7 +37,7 @@ pub fn parse_webhook_inner_payload(webhook: &WebhookPayload) -> WebhookInnerPayl
|
||||
}
|
||||
|
||||
/// Extract the first `msg` and `type` from `payload.detail[]`.
|
||||
fn extract_first_detail(payload: &Option<Value>) -> (Option<String>, Option<WebhookErrorType>) {
|
||||
fn extract_error_first_detail(payload: &Option<Value>) -> (Option<String>, Option<WebhookErrorType>) {
|
||||
let payload = match payload {
|
||||
Some(p) => p,
|
||||
None => return (None, None),
|
||||
@@ -104,7 +104,7 @@ mod tests {
|
||||
WebhookInnerPayload::Error(data) => {
|
||||
assert_eq!(
|
||||
data.error_type,
|
||||
Some(WebhookErrorType::Unknown("invalid_api_key".to_string())),
|
||||
Some(WebhookErrorType::InvalidApiKey),
|
||||
);
|
||||
assert_eq!(
|
||||
data.message.as_deref(),
|
||||
|
||||
@@ -31,6 +31,7 @@ pub enum WebhookErrorType {
|
||||
InvalidArchive,
|
||||
ArchiveFileCountBelowMinimum,
|
||||
ArchiveFileCountExceedsMaximum,
|
||||
InvalidApiKey,
|
||||
|
||||
/// Catch-all for unrecognized error types from FAL.
|
||||
#[serde(untagged)]
|
||||
@@ -75,6 +76,7 @@ mod tests {
|
||||
("\"invalid_archive\"", WebhookErrorType::InvalidArchive),
|
||||
("\"archive_file_count_below_minimum\"", WebhookErrorType::ArchiveFileCountBelowMinimum),
|
||||
("\"archive_file_count_exceeds_maximum\"", WebhookErrorType::ArchiveFileCountExceedsMaximum),
|
||||
("\"invalid_api_key\"", WebhookErrorType::InvalidApiKey),
|
||||
];
|
||||
|
||||
for (json, expected) in cases {
|
||||
|
||||
Reference in new issue
Block a user