googleapis / googleapis/google-api-ruby-client

403 ClientError is misleading when export is too large

Ouverte
#906 1 commentaire 3 réactions 0 personnes assignées Voir sur GitHub
type: feature request
Langage dominant
Ruby
Étoiles
2.9k
Forks
888
Merge moyen
6 min
PR mergées (30 j)
218

Description

Thanks for stopping by to let us know something could be better!

**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.

**Is your feature request related to a problem? Please describe.**

My team is using the client to download files. A line like:

```
client.export_file(file.id, 'application/pdf', :download_dest => StringIO.new).string
```

Is raising a `Google::Apis::ClientError` with an `e.inspect` like:

```
#, @request_absolute_uri=nil, @dumped=false, @request_method="GET", @reason_phrase="Forbidden", @request_uri=#, @http_version="1.1", @body_date=nil, @is_request=false, @request_query={"alt"=>"media", "mimeType"=>"application/pdf"}, @body_size=0, @status_code=403, @body_type=nil, @chunked=false, @header_item=[["Vary", "Origin"], ["Vary", "X-Origin"], ["Content-Type", "application/json; charset=UTF-8"], ["Content-Encoding", "gzip"], ["Date", "Tue, 08 Sep 2020 18:00:04 GMT"], ["Expires", "Tue, 08 Sep 2020 18:00:04 GMT"], ["Cache-Control", "private, max-age=0"], ["X-Content-Type-Options", "nosniff"], ["X-Frame-Options", "SAMEORIGIN"], ["Content-Security-Policy", "frame-ancestors 'self'"], ["X-XSS-Protection", "1; mode=block"], ["Server", "GSE"], ["Alt-Svc", "h3-29=\":443\"; ma=2592000,h3-27=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-T050=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""], ["Transfer-Encoding", "chunked"]], @body_charset=nil>>
```

This threw us for a real loop, because most of these requests work just fine, it was just an occasional file that consistently got a 403. We finally tested the specific file in https://developers.google.com/drive/api/v3/reference/files/export and found that the full response from the API is:

```
{
"error": {
"errors": [
{
"domain": "global",
"reason": "exportSizeLimitExceeded",
"message": "This file is too large to be exported."
}
],
"code": 403,
"message": "This file is too large to be exported."
}
}
```

**Describe the solution you'd like**
It would be great to get that JSON object back in the ClientError's `body` field, or some other mechanism.

**Describe alternatives you've considered**
Right now, we're just having to assume that a 403 from this endpoint means that the file is too large. But that's not great, since https://developers.google.com/drive/api/v3/handle-errors lists a whole bunch of reasons that we might be getting a 403.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par suivre client.export_file et la gestion de Google::Apis::ClientError afin de voir où le corps de la réponse de l'API est traité. Reproduisez la réponse d'exportation surdimensionnée et vérifiez que ClientError expose le corps de l'erreur JSON ou une autre représentation exploitable, sans perdre les autres détails du 403.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
ruby
Domaine
api, backend
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.