0

I am using hasura for queries.

    ApolloNetworkClass.shared.apolloClient.fetch(query: GetCollectionsQuery(user_id: "120"), cachePolicy: .fetchIgnoringCacheData) { (result) in
        switch result
        {
        case .success(let result) :
            if let array = result.data?.nftCollections.map({$0.fragments.nftCollectionsModel})
            {
                self.collectionList = array
                
                self.tblCollections.reloadData()
            }
            else if let error = result.errors {
                if let errorResponse = error.first {
                    print(errorResponse)
                } else {
                    print("[Error] Got errors when call request: \(error)")
                }
            }
            break
        case .failure(let error) :
            Utility.ShowToast(message: error.localizedDescription, position: .top)
            print(error)
            break
        }
    }

Here is my query and I just want to get error code or response code (like 401).

I have tried everything, but I am unable to get solutions.

Thanks in advance.

Punit
  • 3
  • 3

1 Answers1

0

GraphQL error responses will still return a status code 200, unlike the REST API pattern where you will receive a 4xx if something goes wrong.

In order to parse the error message, you will need to look into the response object which would be of the format:

{
  "data": ....,
  "errors": []
}

You can then expand on the errors object which will contain information like the error code, location of the error via some path etc.
praveenweb
  • 743
  • 4
  • 15