Currently, "error responses" from OpenAI (such as when a bad API token is used) are not treated as errors.
This means that the response is fed through to the parser, and fails to decode.
The coder sees a decoding error, rather than the actual problem.
By throwing earlier - we can give a more helpful response in the console.
e.g.
RequestFailed: genericError(error: OpenAISwift.OpenAIError.badResponse(code: 401, response: Optional("{\n \"error\": {\n \"message\": \"Incorrect API key provided: ##YOUR C******************EY##. You can find your API key at https://platform.openai.com/account/api-keys.\",\n \"type\": \"invalid_request_error\",\n \"param\": null,\n \"code\": \"invalid_api_key\"\n }\n}\n")))
Currently, "error responses" from OpenAI (such as when a bad API token is used) are not treated as errors. This means that the response is fed through to the parser, and fails to decode.
The coder sees a decoding error, rather than the actual problem.
By throwing earlier - we can give a more helpful response in the console.
e.g.
RequestFailed: genericError(error: OpenAISwift.OpenAIError.badResponse(code: 401, response: Optional("{\n \"error\": {\n \"message\": \"Incorrect API key provided: ##YOUR C******************EY##. You can find your API key at https://platform.openai.com/account/api-keys.\",\n \"type\": \"invalid_request_error\",\n \"param\": null,\n \"code\": \"invalid_api_key\"\n }\n}\n")))