AuthRPCResponse.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. protocol AuthRPCResponse {
  16. /// Bare initializer for a response.
  17. init()
  18. /** @fn setFieldsWithDictionary:error:
  19. @brief Sets the response instance from the decoded JSON response.
  20. @param dictionary The dictionary decoded from HTTP JSON response.
  21. @param error An out field for an error which occurred constructing the request.
  22. @return Whether the operation was successful or not.
  23. */
  24. func setFields(dictionary: [String: AnyHashable]) throws
  25. /** @fn clientErrorWithshortErrorMessage:detailErrorMessage
  26. @brief This optional method allows response classes to create client errors given a short error
  27. message and a detail error message from the server.
  28. @param shortErrorMessage The short error message from the server.
  29. @param detailErrorMessage The detailed error message from the server.
  30. @return A client error, if any.
  31. */
  32. func clientError(shortErrorMessage: String, detailedErrorMessage: String?) -> Error?
  33. }
  34. extension AuthRPCResponse {
  35. // Default implementation.
  36. func clientError(shortErrorMessage: String, detailedErrorMessage: String? = nil) -> Error? {
  37. return nil
  38. }
  39. }