Module: Hook0::Generated

Defined in:
lib/hook0/generated/api.rb,
lib/hook0/generated/errors.rb,
lib/hook0/generated/models.rb

Overview

Everything the API declares, as the values a caller reads and writes.

Defined Under Namespace

Modules: ApplicationInfoOnboardingStepsEvent, ApplicationInfoOnboardingStepsEventType, ApplicationInfoOnboardingStepsSubscription, OrganizationInfoOnboardingStepsApplication, OrganizationInfoOnboardingStepsEvent, OrganizationInfoOnboardingStepsEventType, OrganizationInfoOnboardingStepsSubscription, ProblemId, RequestAttemptStatusType Classes: Application, ApplicationInfo, ApplicationInfoConsumption, ApplicationInfoOnboardingSteps, ApplicationInfoQuotas, ApplicationNameMissingError, ApplicationPost, ApplicationSecret, ApplicationSecretPost, ApplicationSecretsApi, ApplicationsApi, AuthApplicationSecretLookupErrorError, AuthBiscuitLookupErrorError, AuthEmailAlreadyVerifiedError, AuthEmailExpiredError, AuthEmailNotVerifiedError, AuthFailedLoginError, AuthFailedRefreshError, AuthInvalidApplicationSecretError, AuthInvalidAuthorizationHeaderError, AuthInvalidBiscuitError, AuthNoAuthorizationHeaderError, ErrorsApi, Event, EventAlreadyIngestedError, EventInvalidBase64PayloadError, EventInvalidJsonPayloadError, EventInvalidPayloadContentTypeError, EventPost, EventType, EventTypeAlreadyExistError, EventTypeDoesNotExistError, EventTypePost, EventTypesApi, EventWithPayload, EventsApi, EventsPerDayApi, EventsPerDayEntry, ForbiddenError, IngestedEvent, InstanceApi, InstanceConfig, InstanceConfigFormbricks, InstanceConfigMatomo, InternalServerErrorError, InvalidDateRangeError, InvalidRoleError, InvitedUserAlreadyInOrganizationError, InvitedUserDoesNotExistError, JsonPayloadError, LabelsAmbiguityError, NotFoundError, Organization, OrganizationInfo, OrganizationInfoConsumption, OrganizationInfoOnboardingSteps, OrganizationInfoPlan, OrganizationInfoQuotas, OrganizationInfoUsers, OrganizationIsNotEmptyError, OrganizationNameMissingError, OrganizationPlan, PasswordNotDiverseEnoughError, PasswordSimilarToEmailError, PasswordSimilarToNameError, PasswordTooCommonError, PasswordTooLongError, PasswordTooShortError, PayloadContentTypesApi, Problem, ProblemError, QuotasApi, QuotasResponse, QuotasResponseLimits, RateLimitedError, RegistrationDisabledError, ReplayEvent, RequestAttempt, RequestAttemptEvent, RequestAttemptStatus, RequestAttemptSubscription, RequestAttemptsApi, Response, ResponseApi, ServiceToken, ServiceTokenApi, ServiceTokenPost, ServiceUnavailableError, Subscription, SubscriptionPost, SubscriptionPostTarget, SubscriptionTarget, SubscriptionsApi, TooManyApplicationsPerOrganizationError, TooManyEventTypesPerApplicationError, TooManyEventsTodayError, TooManyMembersPerOrganizationError, TooManySubscriptionsPerApplicationError, UnauthorizedWorkersError, UserAlreadyExistError, ValidationError

Constant Summary collapse

PROBLEMS =

The exception each problem the API names is raised as.

{
  ProblemId::APPLICATION_NAME_MISSING => ApplicationNameMissingError,
  ProblemId::AUTH_APPLICATION_SECRET_LOOKUP_ERROR => AuthApplicationSecretLookupErrorError,
  ProblemId::AUTH_BISCUIT_LOOKUP_ERROR => AuthBiscuitLookupErrorError,
  ProblemId::AUTH_EMAIL_ALREADY_VERIFIED => AuthEmailAlreadyVerifiedError,
  ProblemId::AUTH_EMAIL_EXPIRED => AuthEmailExpiredError,
  ProblemId::AUTH_EMAIL_NOT_VERIFIED => AuthEmailNotVerifiedError,
  ProblemId::AUTH_FAILED_LOGIN => AuthFailedLoginError,
  ProblemId::AUTH_FAILED_REFRESH => AuthFailedRefreshError,
  ProblemId::AUTH_INVALID_APPLICATION_SECRET => AuthInvalidApplicationSecretError,
  ProblemId::AUTH_INVALID_AUTHORIZATION_HEADER => AuthInvalidAuthorizationHeaderError,
  ProblemId::AUTH_INVALID_BISCUIT => AuthInvalidBiscuitError,
  ProblemId::AUTH_NO_AUTHORIZATION_HEADER => AuthNoAuthorizationHeaderError,
  ProblemId::EVENT_ALREADY_INGESTED => EventAlreadyIngestedError,
  ProblemId::EVENT_INVALID_BASE64_PAYLOAD => EventInvalidBase64PayloadError,
  ProblemId::EVENT_INVALID_JSON_PAYLOAD => EventInvalidJsonPayloadError,
  ProblemId::EVENT_INVALID_PAYLOAD_CONTENT_TYPE => EventInvalidPayloadContentTypeError,
  ProblemId::EVENT_TYPE_ALREADY_EXIST => EventTypeAlreadyExistError,
  ProblemId::EVENT_TYPE_DOES_NOT_EXIST => EventTypeDoesNotExistError,
  ProblemId::FORBIDDEN => ForbiddenError,
  ProblemId::INTERNAL_SERVER_ERROR => InternalServerErrorError,
  ProblemId::INVALID_DATE_RANGE => InvalidDateRangeError,
  ProblemId::INVALID_ROLE => InvalidRoleError,
  ProblemId::INVITED_USER_ALREADY_IN_ORGANIZATION => InvitedUserAlreadyInOrganizationError,
  ProblemId::INVITED_USER_DOES_NOT_EXIST => InvitedUserDoesNotExistError,
  ProblemId::JSON_PAYLOAD => JsonPayloadError,
  ProblemId::LABELS_AMBIGUITY => LabelsAmbiguityError,
  ProblemId::NOT_FOUND => NotFoundError,
  ProblemId::ORGANIZATION_IS_NOT_EMPTY => OrganizationIsNotEmptyError,
  ProblemId::ORGANIZATION_NAME_MISSING => OrganizationNameMissingError,
  ProblemId::PASSWORD_NOT_DIVERSE_ENOUGH => PasswordNotDiverseEnoughError,
  ProblemId::PASSWORD_SIMILAR_TO_EMAIL => PasswordSimilarToEmailError,
  ProblemId::PASSWORD_SIMILAR_TO_NAME => PasswordSimilarToNameError,
  ProblemId::PASSWORD_TOO_COMMON => PasswordTooCommonError,
  ProblemId::PASSWORD_TOO_LONG => PasswordTooLongError,
  ProblemId::PASSWORD_TOO_SHORT => PasswordTooShortError,
  ProblemId::RATE_LIMITED => RateLimitedError,
  ProblemId::REGISTRATION_DISABLED => RegistrationDisabledError,
  ProblemId::SERVICE_UNAVAILABLE => ServiceUnavailableError,
  ProblemId::TOO_MANY_APPLICATIONS_PER_ORGANIZATION => TooManyApplicationsPerOrganizationError,
  ProblemId::TOO_MANY_EVENT_TYPES_PER_APPLICATION => TooManyEventTypesPerApplicationError,
  ProblemId::TOO_MANY_EVENTS_TODAY => TooManyEventsTodayError,
  ProblemId::TOO_MANY_MEMBERS_PER_ORGANIZATION => TooManyMembersPerOrganizationError,
  ProblemId::TOO_MANY_SUBSCRIPTIONS_PER_APPLICATION => TooManySubscriptionsPerApplicationError,
  ProblemId::UNAUTHORIZED_WORKERS => UnauthorizedWorkersError,
  ProblemId::USER_ALREADY_EXIST => UserAlreadyExistError,
  ProblemId::VALIDATION => ValidationError
}.freeze

Class Method Summary collapse

Class Method Details

.raise_for_status(status, payload) ⇒ void

This method returns an undefined value.

Raise what the API reported, when what it answered was not a success.

Parameters:

  • status (Integer)

    what the API answered under

  • payload (String)

    the body it answered

Raises:

  • (ProblemError)

    whichever problem the body names, and the base one when it names none



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/hook0/generated/errors.rb', line 219

def self.raise_for_status(status, payload)
  return if status >= 200 && status < 300

  begin
    problem = Problem.from_json(Runtime.decode_payload(payload))
  rescue Runtime::DecodeError
    problem = nil
  end

  if problem.nil? || !PROBLEMS.key?(problem.id)
    raise ProblemError.new(status, problem, Runtime.unreadable(status, payload))
  end

  raise PROBLEMS.fetch(problem.id).new(status, problem, Runtime.reported(status, problem))
end