Method: Cisco::Client::GRPC#handle_json_error
- Defined in:
- lib/cisco_node_utils/client/grpc/client.rb
#handle_json_error(msg) ⇒ Object
Generate a CliError from a failed CliConfigReply
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/cisco_node_utils/client/grpc/client.rb', line 331 def handle_json_error(msg) # { # "cisco-grpc:errors": { # "error": [ # { # "error-type": "application", # "error-tag": "operation-failed", # "error-severity": "error", # "error-message": "....", # }, # { # ... # { # "cisco-grpc:errors": [ # { # "error-type": "protocol", # "error-message": "Failed authentication" # } # ] # } msg = msg['cisco-grpc:errors'] msg = msg['error'] unless msg.is_a?(Array) msg.each do |m| type = m['error-type'] = m['error-message'] || m['error-tag'] += ': ' + m['error-path'] if m['error-path'] if type == 'protocol' && == 'Failed authentication' fail Cisco::AuthenticationFailed, elsif type == 'application' # Example message: # !! SYNTAX/AUTHORIZATION ERRORS: This configuration failed due to # !! one or more of the following reasons: # !! - the entered commands do not exist, # !! - the entered commands have errors in their syntax, # !! - the software packages containing the commands are not active, # !! - the current user is not a member of a task-group that has # !! permissions to use the commands. # # foo # bar # if m['error-path'] fail Cisco::YangError.new( # rubocop:disable Style/RaiseArgs ) else match = /\n\n(.*)\n\n\Z/m.match() if match.nil? rejected = '(unknown, see error message)' else rejected = match[1].split("\n") end fail Cisco::CliError.new( # rubocop:disable Style/RaiseArgs rejected_input: rejected, clierror: , ) end else fail Cisco::ClientError, end end end |