Support Questions
Find answers, ask questions, and share your expertise

Nifi - Capture error message to attribute and route to another process

Nifi - Capture error message to attribute and route to another process

Explorer

My requirement is to capture the error message into attribute and route to another process.

Ex: I am using PutHDFS process where I will load some file, and when I trying to loading duplicate file(same file again) will get some error message like "Routing to failure because file with same name already exists", so I need to capture this message in attribute and route this to new process where i will send email notification.

and any other message will route to another process.

1 REPLY 1
Highlighted

Re: Nifi - Capture error message to attribute and route to another process

Super Guru

@Gurpreet Singh I just checked the code and the failure simply logs the error message.

case FAIL_RESOLUTION:
                                session.transfer(session.penalize(putFlowFile), REL_FAILURE);
                                getLogger().warn("penalizing {} and routing to failure because file with same name already exists",
                                        new Object[]{putFlowFile});
                                return null;
                            default:
                                break;
                        }

However it is very simply to add this error message as a attribute to the flowfile by creating a attribute called error_message" and assigning the attribute the error message. Then you can routeOnAttribute using the error_message attribute.

flowfile = session.putAttribute(flowfile, "error_message", "penalizing {} and routing to failure because file with same name already exists");