Skip to content

Bring Your Own Error Type #448

@moldhouse

Description

@moldhouse

When using the BYOT features with third-party providers, the error format of these APIs often does not match the expectation of this library. For example, this library deserializes errors into this format:

pub struct ApiError {
    pub message: String,
    #[serde(rename = "type")]
    pub r#type: Option<String>,
    pub param: Option<String>,
    #[serde(deserialize_with = "deserialize_code")]
    pub code: Option<String>,
}

However, OpenRouter provides errors in the following format:

{
    "error": {
        "message": "User not found.",
        "code": 401
    }
}

with the small difference that code is an integer, leading to a deserialization error when using this library.

Before implementing a possible "bring-your-own-error-type" feature, I want to check if this would be within the scope of this library, and about how to architect it. One option might be that users bring their own error type for deserialization that must implement a trait to convert itself into an OpenAIError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions