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

org.talend.esb.sam.service.rest.SAMExceptionMapper Maven / Gradle / Ivy

There is a newer version: 8.0.1.R2024-05-RT
Show newest version
package org.talend.esb.sam.service.rest;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

import org.talend.esb.sam.service.rest.exception.IllegalParameterException;
import org.talend.esb.sam.service.rest.exception.ResourceNotFoundException;
import org.talend.esb.sam.service.rest.exception.SamServiceException;

public class SAMExceptionMapper implements ExceptionMapper {

    @Override
    public Response toResponse(SamServiceException exception) {

        Status status;
        if (exception instanceof IllegalParameterException) {
            status = Status.BAD_REQUEST;
        } else if (exception instanceof ResourceNotFoundException) {
            status = Status.NOT_FOUND;
        } else {
            status = Status.INTERNAL_SERVER_ERROR;
        }

        return Response.status(status).type("text/plain").entity(exception.getMessage()).build();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy