Skip to content

Commit c71db36

Browse files
author
Paul Asjes
authored
Add new ForbiddenRequestError (#339)
1 parent 19e477b commit c71db36

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

lib/workos.rb

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def self.key
8888
autoload :APIError, 'workos/errors'
8989
autoload :AuthenticationError, 'workos/errors'
9090
autoload :InvalidRequestError, 'workos/errors'
91+
autoload :ForbiddenRequestError, 'workos/errors'
9192
autoload :SignatureVerificationError, 'workos/errors'
9293
autoload :TimeoutError, 'workos/errors'
9394
autoload :NotFoundError, 'workos/errors'

lib/workos/client.rb

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ def handle_error_response(response:)
109109
http_status: http_status,
110110
request_id: response['x-request-id'],
111111
)
112+
when 403
113+
raise ForbiddenRequestError.new(
114+
message: json['message'],
115+
http_status: http_status,
116+
request_id: response['x-request-id'],
117+
code: json['code'],
118+
data: json,
119+
)
112120
when 404
113121
raise NotFoundError.new(
114122
message: json['message'],

lib/workos/errors.rb

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class AuthenticationError < WorkOSError; end
6464
# parameters.
6565
class InvalidRequestError < WorkOSError; end
6666

67+
# ForbiddenError is raised when a request is forbidden, likely due to missing a step
68+
# (i.e. verifying email ownership before authenticating).
69+
class ForbiddenRequestError < WorkOSError; end
70+
6771
# SignatureVerificationError is raised when the signature verification for a
6872
# webhook fails
6973
class SignatureVerificationError < WorkOSError; end

spec/lib/workos/user_management_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,20 @@
404404
end
405405
end
406406
end
407+
408+
context 'with an unverified user' do
409+
it 'raises a ForbiddenRequestError' do
410+
VCR.use_cassette('user_management/authenticate_with_password/unverified') do
411+
expect do
412+
WorkOS::UserManagement.authenticate_with_password(
413+
414+
password: '7YtYic00VWcXatPb',
415+
client_id: 'client_123',
416+
)
417+
end.to raise_error(WorkOS::ForbiddenRequestError, /Email ownership must be verified before authentication/)
418+
end
419+
end
420+
end
407421
end
408422

409423
describe '.authenticate_with_code' do

spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/unverified.yml

+82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)