Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor find or create Professor errors #11

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/edusign/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,11 @@ def create_professor(first_name:, last_name:, email:)

def find_or_create_professor(first_name:, last_name:, email:)
response = api :get, "/professor/by-email/#{email}"
raise Response::Error, Response::Error::PROFESSOR_NOT_FOUND_ERROR_MESSAGE if response.message == "professor not found"
raise Response::Error, Response::Error::PROFESSOR_DELETED_ERROR_MESSAGE if response.result.present? && response.result[:HIDDEN].any? && response.result[:HIDDEN].include?(response.result[:ID])

response.result
rescue Response::Error => e
raise e unless [Response::Error::PROFESSOR_NOT_FOUND_ERROR_MESSAGE, Response::Error::PROFESSOR_DELETED_ERROR_MESSAGE].include?(e.message) || e.message.include?(Response::Error::CANNOT_GET_PROFESSOR_BY_EMAIL_ERROR_MESSAGE)
raise e unless [Response::Error::PROFESSOR_DELETED_ERROR_MESSAGE].include?(e.message) || e.message.include?(Response::Error::CANNOT_GET_PROFESSOR_BY_EMAIL_ERROR_MESSAGE)

response = create_professor(first_name: first_name, last_name: last_name, email: email)
response.result
Expand Down Expand Up @@ -284,7 +283,6 @@ def options(opts = {})

class Response
class Error < StandardError
PROFESSOR_NOT_FOUND_ERROR_MESSAGE = "professor not found".freeze
PROFESSOR_DELETED_ERROR_MESSAGE = "professor was deleted".freeze
CANNOT_GET_PROFESSOR_BY_EMAIL_ERROR_MESSAGE = "Error - cannot get professor by email".freeze
end
Expand Down