The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

OpenAI::API::Error - throwable error objects

SYNOPSIS

    use OpenAI::API::Error;

    OpenAI::API::Error->throw(
        message  => 'Something went wrong',
        request  => $req,
        response => $res,
    );

    # elsewhere...

    try {
        my $response = $openai->$method(...);
    } catch ($e) {
        # Handle error
    }

DESCRIPTION

The OpenAI::API::Error module provides an object-oriented exception mechanism for errors encountered while interacting with the OpenAI API. It extends the Throwable::Error class to include the optional HTTP::Request and HTTP::Response objects, allowing for better error reporting and debugging.

ATTRIBUTES

request

The request attribute holds the HTTP::Request object associated with the error.

response

The response attribute holds the HTTP::Response object associated with the error.

METHODS

throw

The throw method creates a new OpenAI::API::Error object with the provided message, request, and response attributes and throws it as an exception.

SEE ALSO