-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly handle Amazon GW forbidden errors
The Amazon API gateway used by the Easee API seems to route some requests to a blackhole, possibly because we keep trying to login with outdated credentials. However, such responses should result in a Forbidden error to make sure they're dealt with correctly upstream. This PR adds a Faraday middleware that detects the Amazon Forbidden response header and changes the response status code to 403.
- Loading branch information
1 parent
6dfe564
commit 070c451
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Easee | ||
class AmazonGwMiddleware < Faraday::Middleware | ||
def on_complete(env) | ||
return unless env.response_headers["X-Amzn-Errortype"] == "ForbiddenException" | ||
|
||
response_values = Faraday::Response::RaiseError.new.response_values(env) | ||
raise(Faraday::ForbiddenError, response_values) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters