**Bean-Component for Credential entry form**

```
  public class UserCredentials {

    private String username;
    private String password;

    public UserCredentials() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

```

**resource**

```
@Path("auth")
   public class AuthenticationResource {
    @POST
    @Consumes( MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @PermitAll
    public Response authenticateUserName(UserCredentials credentials)  {

        EmployeeDao dao = new EmployeeDaoImpl();
        Employee email = dao.loadEmployeeByFieldStr("email", credentials.getUsername());

        if(email == null){
            throw new AccessDeniedException("Non found!");
        }

        credentials.setUsername(email.getEmail());
        Response response = Response.ok(credentials).build();

        return response;
    }

```

**model for storing error details**

```
@JsonInclude( JsonInclude.Include.NON_NULL)
public class ApiErrorDetails {

    private Integer status;
    private String title;
    private String message;
    private String path;

    public ApiErrorDetails() {
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setPath(String path) {
        this.path = path;
    }

}

```

**ExceptionMapper**

```
     @Provider
       public class AccessDeniedExceptionMapper 
              implements   ExceptionMapper<AccessDeniedException> {

        @Context
        private UriInfo uriInfo;

        @Override
        public Response toResponse(AccessDeniedException exception) {

            Response.Status status = Response.Status.UNAUTHORIZED; 

            ApiErrorDetails errorDetails = new ApiErrorDetails();

            errorDetails.setStatus(status.getStatusCode());
            errorDetails.setTitle(status.getReasonPhrase());
            errorDetails.setMessage(exception.getMessage());

            errorDetails.setPath(uriInfo.getAbsolutePath().getPath());

            Response.ResponseBuilder statusResponse = Response.status(status);
            Response.ResponseBuilder entity =  
                                        statusResponse.entity(errorDetails);
            Response.ResponseBuilder type = 
                              entity.type(MediaType.APPLICATION_JSON);
            Response response = type.build();

            return response;
        }
    }

```

**registration config**

```
@ApplicationPath("/api/*")
public class JerseyConfig  extends ResourceConfig {

    public JerseyConfig() {

        packages("com.skillsimprover.restexamples.rest");
        register(AuthenticationResource.class);
        register(AccessDeniedExceptionMapper.class);
        register(AuthenticationExceptionMapper.class);
        register(DataNotFoundExceptionMapper.class);
    }
}

```

**web.xml**

```
<servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.skillsimprover.restexamples.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>

```

pom.xml

```
<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.27</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.rest.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <version>2.26</version>     
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlets.version}</version>
        <scope>provided</scope>
    </dependency>

</dependencies>

```

When **RuntimeException** strikes, it must be intercepted by Jersey classes that implement the **ExceptionMapper** interface.

During debugging, I observed how the **response** was formed with the details of the errors in the **AccessDeniedExceptionMapper** class.
 But on the client side, I only get the status code, which is all set, and instead of the **JSON** object with the details of the errors, here are the empty parentheses {}.

Why?