How can I avoid 40x error from logging as ERROR?

module Bookshelf
  module Actions
    module Books
      class Index < Bookshelf::Action
        handle_exception RecordNotFound => :handle_not_found_error

        def handle(*, response)
          raise RecordNotFound
        end

        private
        
        def handle_standard_error(request, response, exception)
          halt 404
        end
      end
    end
  end
end

The code above logs the following firstly.

[bookshelf] [ERROR] [2023-08-04 16:03:16 +0000] POST 500 0µs 192.168.80.1 /hoge 106 app="bookshelf" http="HTTP/1.0"

in accord with the code of dry-monitor

Secondly it logs the following.

[bookshelf] [INFO] [2023-08-04 16:03:16 +0000] POST 403 830ms 192.168.80.1 /hoge 106 app="bookshelf" http="HTTP/1.0"

in accord with the code of dry-monitor

I think it is odd that first logging is treated as ERROR, not WARN or INFO.
How can I avoid 40x error from logging as ERROR?

Thanks for this report, @MasanoriOnishi, this looks like a bug to me — handled errors should not be logged as errors at all, IMO. I’ll put it on the list to look at for our next release.

1 Like

Of course, I’d welcome anyone’s efforts if they’d like to have a go at fixing this!

1 Like

Thank you for your reply and nice suggestion…!!

Hi @MasanoriOnishi I’m happy to share that I’ve now fixed this bug: Fix error logging on handled exceptions by timriley · Pull Request #1337 · hanami/hanami · GitHub

This should make it into 2.1.0.beta2 that we are planning to release around the 11th of October. We’re working hard to move from the betas to 2.1.0 proper, so hopefully you won’t be waiting too long before it’s in a stable release.

Thanks again for your report! :heart:

1 Like

@timriley

Thank you for your fast fix…!!
I’m looking forward to update new version!!