m1guelpf / plz-cli

Copilot for your terminal
MIT License
1.58k stars 78 forks source link

Fix #2: Print more information on failed requests #20

Closed soerface closed 1 year ago

soerface commented 1 year ago

Discriminate between server and client errors. If it's a client error, parse the JSON to pretty print the failure reason. I assume that every client error response looks similar (contains error.message).

This is the response I got because a payment method was missing:

$ curl -X POST https://api.openai.com/v1/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "top_p": 1,
    "stop": "```",
    "temperature": 0,
    "suffix": "\n```",
    "max_tokens": 1000,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "model": "text-davinci-003",
    "prompt": "your prompt"                
}'

{
    "error": {
        "message": "You exceeded your current quota, please check your plan and billing details.",
        "type": "insufficient_quota",
        "param": null,
        "code": null
    }
}

Fixes #2