Skip to content

v0.2.0

Latest

Choose a tag to compare

@davidesantangelo davidesantangelo released this 28 Oct 15:19
· 1 commit to master since this release

What's New

Structured Error Classes

Error handling is now much more robust and informative. All API errors now include contextual information to help you diagnose issues faster:

begin
  client.flows
rescue Node::Red::BadRequestError => e
  puts "Status: #{e.status}"        # => 400
  puts "Code: #{e.code}"             # => "invalid_request"
  puts "Details: #{e.details.inspect}" # => Full parsed response body
end

New error classes:

  • BadRequestError - Raised for HTTP 400 responses (malformed requests)
  • ConflictError - Raised for HTTP 409 responses (version conflicts)
  • UnexpectedResponseError - Raised for unexpected response types

Enhanced existing errors:

  • AuthenticationError - Now includes structured context (HTTP 401)
  • NotFoundError - Now includes structured context (HTTP 404)
  • ServerError - Now includes structured context (HTTP 5xx)

Comprehensive Test Coverage

Added extensive WebMock-backed RSpec tests covering:

  • ✅ Every Admin API endpoint (auth, flows, nodes, settings, diagnostics)
  • ✅ All error paths and edge cases
  • ✅ Authorization header handling
  • ✅ Empty response bodies
  • ✅ Invalid JSON responses
  • ✅ Various HTTP status codes

This ensures reliability and makes future contributions easier!

Improvements

Better Error Handling

The client now intelligently maps Node-RED response codes to dedicated exceptions:

  • 400 → BadRequestError
  • 401 → AuthenticationError
  • 404 → NotFoundError
  • 409 → ConflictError
  • 5xx → ServerError
  • Other unexpected responses → UnexpectedResponseError

Enhanced JSON Parsing

Response and error parsing now includes safeguards for:

  • Empty response bodies
  • Invalid JSON
  • Missing error fields
  • Malformed content

This prevents cryptic parsing errors and provides clearer diagnostics.

Updated Documentation

The README now includes advanced error-handling guidance with examples showing how to access error context for debugging.

Dependencies

Added webmock ~> 3.19 for HTTP request stubbing in tests.

Migration Guide

If you're upgrading from v0.1.0, no breaking changes were introduced! Your existing code will continue to work. However, you can now optionally access richer error information:

Before:

rescue Node::Red::ApiError => e
  puts e.message
end

After (optional enhancement):

rescue Node::Red::ApiError => e
  puts "Error: #{e.message}"
  puts "HTTP Status: #{e.status}"
  puts "Error Code: #{e.code}" if e.code
  puts "Details: #{e.details.inspect}" if e.details
end

Full Changelog: [View on GitHub](https://github.com/your-repo/node-red-ruby/compare/v0.1.0...v0.2.0)