Skip to content

Commit

Permalink
Add new ForbiddenRequestError (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Asjes authored Jan 6, 2025
1 parent 19e477b commit c71db36
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/workos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def self.key
autoload :APIError, 'workos/errors'
autoload :AuthenticationError, 'workos/errors'
autoload :InvalidRequestError, 'workos/errors'
autoload :ForbiddenRequestError, 'workos/errors'
autoload :SignatureVerificationError, 'workos/errors'
autoload :TimeoutError, 'workos/errors'
autoload :NotFoundError, 'workos/errors'
Expand Down
8 changes: 8 additions & 0 deletions lib/workos/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ def handle_error_response(response:)
http_status: http_status,
request_id: response['x-request-id'],
)
when 403
raise ForbiddenRequestError.new(
message: json['message'],
http_status: http_status,
request_id: response['x-request-id'],
code: json['code'],
data: json,
)
when 404
raise NotFoundError.new(
message: json['message'],
Expand Down
4 changes: 4 additions & 0 deletions lib/workos/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class AuthenticationError < WorkOSError; end
# parameters.
class InvalidRequestError < WorkOSError; end

# ForbiddenError is raised when a request is forbidden, likely due to missing a step
# (i.e. verifying email ownership before authenticating).
class ForbiddenRequestError < WorkOSError; end

# SignatureVerificationError is raised when the signature verification for a
# webhook fails
class SignatureVerificationError < WorkOSError; end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/workos/user_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@
end
end
end

context 'with an unverified user' do
it 'raises a ForbiddenRequestError' do
VCR.use_cassette('user_management/authenticate_with_password/unverified') do
expect do
WorkOS::UserManagement.authenticate_with_password(
email: '[email protected]',
password: '7YtYic00VWcXatPb',
client_id: 'client_123',
)
end.to raise_error(WorkOS::ForbiddenRequestError, /Email ownership must be verified before authentication/)
end
end
end
end

describe '.authenticate_with_code' do
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c71db36

Please sign in to comment.