google-api-swift-client icon indicating copy to clipboard operation
google-api-swift-client copied to clipboard

Improve error handling by using Result<Z, Error> instead of (Z?, Error?)

Open 0xced opened this issue 4 years ago • 2 comments

  • Also properly decode errors when HTTP status code is greater or equal to 400
  • Make all Service.perfom() functions non throwing and return the error through the completion handler if applicable instead

0xced avatar Jan 20 '20 14:01 0xced

After merging and attempting to resolve conflicts, I found a few build errors like the ones below.

It seems to me that this is because we didn't remove throwing from the performRequest methods in google-auth-library-swift. @0xced did you do that in a separate branch/repo? I would support merging that.

$ make
swift build -c debug
/Users/timburks/Desktop/google-api-swift-client/Sources/GoogleAPIRuntime/Service.swift:152:5: error: call can throw, but it is not marked with 'try' and the error is not handled
    connection.performRequest(
    ^
/Users/timburks/Desktop/google-api-swift-client/Sources/GoogleAPIRuntime/Service.swift:169:7: error: call can throw but is not marked with 'try'
      connection.performRequest(
      ^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/timburks/Desktop/google-api-swift-client/Sources/GoogleAPIRuntime/Service.swift:169:7: note: did you mean to use 'try'?
      connection.performRequest(
      ^
      try 
/Users/timburks/Desktop/google-api-swift-client/Sources/GoogleAPIRuntime/Service.swift:169:7: note: did you mean to handle error as optional value?
      connection.performRequest(
      ^
      try? 

timburks avatar Mar 31 '20 17:03 timburks

I have several work in progress branches in both google-auth-library-swift and google-api-swift-client. I will rebase them all, fix the errors and submit new pull requests.

0xced avatar Apr 03 '20 11:04 0xced