View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.restapi.v1.errors;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import jakarta.ws.rs.core.Response.Status;
25  
26  /**
27   * exception that can be thrown during rest api requests
28   * 
29   * @author Robert Stephan
30   * 
31   * @version $Revision: $ $Date: $
32   */
33  public class MCRRestAPIException extends Exception {
34  
35      private static final long serialVersionUID = 1L;
36  
37      private List<MCRRestAPIError> errors = new ArrayList<>();
38  
39      //default is 501 - internal server error, override if necessary
40      private Status status = Status.INTERNAL_SERVER_ERROR;
41  
42      public MCRRestAPIException(Status status, MCRRestAPIError error) {
43          this.status = status;
44          errors.add(error);
45      }
46  
47      public MCRRestAPIException(Status status, List<MCRRestAPIError> errors) {
48          this.status = status;
49          this.errors.addAll(errors);
50      }
51  
52      public List<MCRRestAPIError> getErrors() {
53          return errors;
54      }
55  
56      public Status getStatus() {
57          return status;
58      }
59  
60      public void setStatus(Status status) {
61          this.status = status;
62      }
63  }