onfleet / ruby-onfleet

Onfleet API wrapper in Ruby
MIT License
2 stars 2 forks source link

uninitialized constant Onfleet::PermissionError (NameError) #7

Closed jonathandean closed 1 year ago

jonathandean commented 1 year ago

NameError during attempt to retrieve the task list when auth permissions are incorrectly configured

gems/ruby-onfleet-1.0.2/lib/utils.rb:50:in `handle_api_error': uninitialized constant Onfleet::PermissionError (NameError)     

      raise PermissionError, "status: #{response.status}, message: #{response.body}"
jonathandean commented 1 year ago

a simple option seems to be adding these at the top of utils.rb

require 'errors/http_error'
require 'errors/permission_error'
require 'errors/service_error'

It's a bit odd that the message comes back as html but that's another thing

 (Onfleet::PermissionError) gems/ruby-onfleet-1.0.2/lib/utils.rb:53:in `handle_api_error': status: 403, message: <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
</body>
</html>
jonathandean commented 1 year ago

For reference this permission error was due to trying to access the staging environment endpoint. The same API key worked without specifying an endpoint and hence defaulting to the production API