package com.iqser.red.service.persistence.management.v1.processor.service;

import org.springframework.http.HttpStatus;

import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;

import feign.FeignException;

public final class FeignExceptionHandler {

    private FeignExceptionHandler() {}


    public static RuntimeException processFeignException(FeignException e) {

        if (e.status() == HttpStatus.NOT_FOUND.value()) {
            return new NotFoundException(e.getMessage(), e);
        }
        if (e.status() == HttpStatus.BAD_REQUEST.value()) {
            return new BadRequestException(e.getMessage(), e);
        }
        if (e.status() == HttpStatus.CONFLICT.value()) {
            throw new ConflictException(e.getMessage(), e);
        }
        return e;
    }

}
