husnjak / IGDB-SWIFT-API

A Swift wrapper for the IGDB.com Free Video Game Database API.
MIT License
59 stars 11 forks source link

Issue while loading entries from database #10

Open StepanPazderka opened 3 years ago

StepanPazderka commented 3 years ago

I am trying to use this package with example code, I ahve setup Access Token and ClientID, but this error is raised up everytime

Fatal error: 'try!' expression unexpectedly raised an error: SwiftProtobuf.BinaryDecodingError.truncated: file IGDB_SWIFT_API/ProtoRequest.swift, line 107

husnjak commented 3 years ago

@StepanPazderka Can I get some more information about this? i am interested in the query and the code used

EthanG45 commented 3 years ago

This looks kind of similar to the error you get when you do too many requests at once? Not sure if that's possibly related.

StepanPazderka commented 3 years ago

This is the source code that produces this error, it is possible that I am doing some newbie mistake. I am a junior swifter at this point:

Please add your api keys and access tokens

override func viewDidLoad() {
        super.viewDidLoad()

        let wrapper = IGDBWrapper(clientID: "", accessToken: "")

        let apicalypse = APICalypse()
            .fields(fields: "*")
            .sort(field: "release_dates.date", order: .DESCENDING)

        wrapper.games(apiCalypse: apicalypse, result: { games in
            // Do something..
        }) { error in
            // Do something..
        }
    }
husnjak commented 3 years ago

When I am running your code in a test it seems to work just fine. thinking of @EthanG45 comment does this happen all the time for you? or just after some requests? Because there is a rate-limit on the api that is 4 requests/second and if you exceed that you will get an error instead. Also does your queries work in a api client such as Postman or Insomia?

EthanG45 commented 3 years ago

I just wrote up a proof of concept game library app using the API in SwiftUI, and the only time I really saw errors were when I sent invalid queries or hit that rate limit. @StepanPazderka did you setup your API access token and what not properly?

Also @husnjak can I hijack and ask if you have a recommended way to catch errors when we do hit the rate limit? I'm also pretty new to programming in Swift and was unclear how to make use of the error closures provided.

StepanPazderka commented 3 years ago

Could be that my tokens are not setup correctly. Sorry for that. I am not able to figure it out on my own, so if this API would do a better error handling with description for such cases, it would be great.

EthanG45 commented 3 years ago

Could be that my tokens are not setup correctly. Sorry for that. I am not able to figure it out on my own, so if this API would do a better error handling with description for such cases, it would be great.

The console gives a descriptive message of where the error occurred and the response from IGDB. For instance spamming requests will show you the line where it attempted to generate a Proto_Game object and also say something like response too many requests at once.

I'm not sure what other messaging you'd want?

observableobject commented 3 years ago

Just leaving a comment here that I get this error as well in Xcode 12, even when copying in the examples in the Readme. It doesn't say anything about too many requests, it appears that the data is malformed.

Fatal error: 'try!' expression unexpectedly raised an error: SwiftProtobuf.BinaryDecodingError.malformedProtobuf: file IGDB_SWIFT_API/ProtoRequest.swift, line 107 (lldb)

I may create a new issue, if I can't figure out a solution. Thanks!