# frozen_string_literal: true RSpec.describe Fiken::Error do describe ".from_response" do it "maps known statuses to specific subclasses" do { 400 => Fiken::BadRequest, 401 => Fiken::Unauthorized, 403 => Fiken::Forbidden, 404 => Fiken::NotFound, 422 => Fiken::UnprocessableEntity, 429 => Fiken::RateLimited }.each do |status, klass| expect(described_class.from_response(status, {})).to be_a(klass) end end it "maps unknown 5xx statuses to ServerError" do expect(described_class.from_response(503, "")).to be_a(Fiken::ServerError) end it "extracts a message from a JSON error body" do error = described_class.from_response(400, { "message" => "Bad slug" }) expect(error.message).to eq("Bad slug") expect(error.status).to eq(400) end it "falls back to a generic message when the body has none" do error = described_class.from_response(404, "") expect(error.message).to eq("Fiken API error (HTTP 404)") end end end