Sha256: 1dbc014de86037bd6e0310de8db31a884e2dc846bd649b0fb15fb30ae80d938b

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

module LifenFhir

  class AppAuthenticatedClient < Client

    private

      def handle_errors(response, params)
        super(response, params)

        case response.status
        when 400
          raise Error, "Error 400, Unknown error, #{response_error(response, params)}"
        when 401
          raise InvalidSecretTokenError, "Error 401, Invalid app bearer, #{response_error(response, params)}"
        when 403
          raise UserAlreadyExistingError, "Error 403, User already existing, #{response_error(response, params)}"
        when 404
          raise Error, "Error 404, Page not found, #{response_error(response, params)}"
        when 422
          json = JSON.parse response.body

          diagnostic = json["issue"][0]["diagnostics"]

          raise Error, "Error 422, Unprocessable Entity, Diagnostic: '#{diagnostic}', #{response_error(response, params)}"
        end

      end

      def response_error(response, params)
        "App Client, #{super(response, params)}"
      end

      def bearer
        LifenFhir.configuration.application_access_token
      end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lifen_fhir-0.5.0 lib/lifen_fhir/app_authenticated_client.rb
lifen_fhir-0.4.2 lib/lifen_fhir/app_authenticated_client.rb
lifen_fhir-0.4.1 lib/lifen_fhir/app_authenticated_client.rb
lifen_fhir-0.4.0 lib/lifen_fhir/app_authenticated_client.rb
lifen_fhir-0.3.0 lib/lifen_fhir/app_authenticated_client.rb
lifen_fhir-0.2.0 lib/lifen_fhir/app_authenticated_client.rb
lifen_fhir-0.1.1 lib/lifen_fhir/app_authenticated_client.rb