Maybe I'm just completely overthinking this but I am trying to use enums to handle errors from an API I am integrating with.
From the swagger documentation of this API I can see all of the possible responses that could be returned. I have written these out as a BaseError
enum:
enum BaseError: Error {
case badRequest // 400
case unauthorized // 401
case forbidden // 403
case unhandledError // XXX
...
}
Now in my client is where my problem starts.
My original hope was to take this BaseError
enum and extend / add additional cases onto it depending on which client I am in.
Something like:
enum ClientSpecificError: BaseError {
case clientError
}
Which would allow me to return an error like ClientSpecificError.unauthorized
Now I know this is not possible as enums cannot inherit other enums but I am missing some understanding on how I should accomplish this.
Questions
Is there some other way I can use enums to accomplish this?
Is this even a "best practice"?