strlen( $text ), 'text_preview' => substr( $text, 0, 100 ), ) ); } /** * Create exception for API failure * * @since 1.0.0 * @param string $api_error API error message. * @param int $status_code HTTP status code. * @return self. */ public static function api_failure( string $api_error, int $status_code = 500 ): self { return new self( 'Audio generation API request failed', $status_code, null, array( 'api_error' => $api_error, 'status_code' => $status_code, ) ); } /** * Create exception for file write failure * * @since 1.0.0 * @param string $file_path File path that failed. * @return self. */ public static function file_write_failure( string $file_path ): self { return new self( 'Failed to write audio file', 500, null, array( 'file_path' => $file_path, 'permissions' => fileperms( dirname( $file_path ) ), ) ); } /** * Create exception for unsupported format * * @since 1.0.0 * @param string $format Unsupported format. * @param array $supported_formats Supported formats. * @return self. */ public static function unsupported_format( string $format, array $supported_formats ): self { return new self( 'Unsupported audio format requested', 400, null, array( 'requested_format' => $format, 'supported_formats' => $supported_formats, ) ); } }