05eae9d7e5ffc9ba96c83607c29f6005ea685eb7
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.common.errors;
18
19 import org.apache.commons.text.RandomStringGenerator;
20
21 public class GeneralErrorBuilder {
22
23   private static final String GENERAL_ERROR_REST_ID = "GENERAL_ERROR_REST_ID";
24   private static final String GENERAL_ERROR_REST_MSG =
25           "An internal error has occurred. Please contact support. Error ID: %s";
26
27   private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
28
29   /**
30    * Instantiates a new General error builder.
31    */
32   public GeneralErrorBuilder() {
33     RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('A', 'Z').build();
34     builder.withId(GENERAL_ERROR_REST_ID);
35     builder.withCategory(ErrorCategory.APPLICATION);
36     builder.withMessage(String.format(GENERAL_ERROR_REST_MSG, generator.generate(8)));
37   }
38
39   public ErrorCode build() {
40     return builder.build();
41   }
42
43 }