All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.khasanof.executors.processor.ExceptionChainProcessor Maven / Gradle / Ivy

The newest version!
package org.khasanof.executors.processor;

import lombok.extern.slf4j.Slf4j;
import org.khasanof.constants.FluentConstants;
import org.khasanof.context.FluentThreadLocalContext;
import org.khasanof.service.exception.ExceptionResolver;
import org.khasanof.service.exception.ExceptionResolverService;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.objects.Update;

import java.util.Objects;

/**
 * @author Nurislom
 * @see org.khasanof.executors.processor
 * @since 1/25/2024 10:32 PM
 */
@Slf4j
public class ExceptionChainProcessor extends AbstractUpdateChainProcessor {

    private final ExceptionResolverService exceptionResolver;

    public ExceptionChainProcessor(ExceptionResolverService exceptionResolver) {
        this.exceptionResolver = exceptionResolver;
    }

    @Override
    public void process(Update update) throws Exception {
         try {
             tryProcess(update);
         } catch (Exception ex) {
             catchException(update, ex);
         }
    }

    private void tryProcess(Update update) throws Exception {
        callNextProcess(update);
    }

    private void catchException(Update update, Exception ex) throws Exception {
        exceptionResolver.resolve(new ExceptionResolver(update, ex));
    }

    @Override
    public int getOrder() {
        return FluentConstants.HIGH_ORDER;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy