buildasaurs / XcodeServerSDK

Access Xcode Server API with native Swift objects.
MIT License
399 stars 30 forks source link

Change API call signatures to use ErrorType instead of NSError #81

Open cojoj opened 8 years ago

cojoj commented 8 years ago

Right now most of our API endpoint methods (these located in XcodeServer extensions) are constructed in non-swifty way - they return optional NSError pointers.

How about gradually changing them to throwing methods? There are some benefits of doing this:

  1. Swifty way (most important argument... 😜)
  2. Reduce amount of Optionals
  3. More descriptive errors, as they'll be enums

I know, I know, I may be overreacting... Maybe that's because I have too much free time? 😝

czechboy0 commented 8 years ago

Can you provide an example? AFAIK, all our APIs are asynchronous, so the callback block is called much later after the call of the API method. Throw only works with synchronous calls.

What we could do is change the signature from NSError to ErrorType. That would be a good improvement, because it would allow for error enum types.

cojoj commented 8 years ago

Right, async... And I'm back home 😉 But we have more methods which may be considered this way eg. createRequest() returns NSMutableRequest?.

Anyway, ErrorTypes sounds great!

czechboy0 commented 8 years ago

Yup, createRequest() would be a good candidate for throwing.

czechboy0 commented 8 years ago

Action: look into changing the error type in API call block callbacks from NSError to ErrorType.