go-routeros / routeros

Go library for accessing Mikrotik devices using the RouterOS API
MIT License
193 stars 48 forks source link

Get a specific error type for authentication failure #26

Open EliRibble opened 2 weeks ago

EliRibble commented 2 weeks ago

As a client of this library I'd like to do different behavior rather than just print out the nested error messages. For example, right now if I just do:

          c, err := routeros.DialTimeout(*address, *username, *password, *timeout)                                                                                                        
          if err != nil {                                                                                                                                                                 
                  fatal(log, err)                                                                                                                                                         
          }                                                                                                                                                                               

The output looks like:

could not login: from RouterOS device: invalid user name or password (6); close %!w()

Instead I'd like to detect that it was an authentication failure, and tell my user their credentials are bad.

EliRibble commented 2 weeks ago

https://github.com/go-routeros/routeros/pull/27 for a solution