Skip to content

Commit

Permalink
raise error on invalid apiKey - release 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoneill committed Mar 18, 2024
1 parent 19c89ff commit 781d5b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

# rspec failure tracking
.rspec_status
*.gem
12 changes: 12 additions & 0 deletions lib/partsdb/custom_cookie_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def handle_request(request_env)
new_env.request_headers = { "Content-Type": "application/json" }

@app.call(new_env).on_complete do |response_env|

# handle invalid api key
# the response body is json and should appear like this:
# {
# "Code": "0000",
# "Message": ""
# }
# check for the Code 0000, which indicates a successful login
if response_env.body["Code"] != "0000"
raise "Invalid API key"
end

@auth_cookie = parse_set_cookie(response_env.response_headers["set-cookie"])
handle_request(request_env)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/partsdb/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Partsdb
VERSION = "0.3.1"
VERSION = "0.3.2"
end

0 comments on commit 781d5b8

Please sign in to comment.