Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTCloudException.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package com.basistech.df.cybertriage.autopsy.ctapi;
20 
21 
22 import java.util.Objects;
23 import org.apache.commons.lang3.StringUtils;
24 import org.apache.commons.lang3.exception.ExceptionUtils;
25 
30 public class CTCloudException extends Exception{
31  private final ErrorCode errorCode;
32 
33  public enum ErrorCode {
34  BAD_REQUEST("CT-400", "Unknown or Bad request. Please contact Basis support at " + Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM + " for help diagnosing the problem."),
35  INVALID_KEY("CT-401", "An invalid license ID was used to access CyberTriage Cloud Service. Please contact Basis support " + Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM + " for help diagnosing the problem."),
36  GATEWAY_TIMEOUT("CT-504", "Request to CyberTriage Cloud Service timed out. Please retry after some time. If issue persists, please contact Basis support at " + Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM + " for assistance."),
37  UN_AUTHORIZED("CT-403", "An authorization error occurred. Please contact Basis support " + Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM + " for help diagnosing the problem."),
38  PROXY_UNAUTHORIZED("CT-407", "Proxy authentication failed. Please validate the connection settings from the Options panel Proxy Settings."),
39  TEMP_UNAVAILABLE("CT-500", "CyberTriage Cloud Service temporarily unavailable; please try again later. If this problem persists, contact Basis support at " + Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM),
40  UNKNOWN("CT-080", "Unknown error while communicating with CyberTriage Cloud Service. If this problem persists, contact Basis support at "+ Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM +" for assistance."),
41  UNKNOWN_HOST("CT-081", "Unknown host error. If this problem persists, contact Basis support at "+ Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM +" for assistance."),
42  NETWORK_ERROR("CT-015", "Error connecting to CyberTriage Cloud.\n"
43  + "Check your firewall or proxy settings.\n"
44  + "Contact Support (support@cybertriage.com) for further assistance");
45  private final String errorcode;
46  private final String description;
47 
48  private ErrorCode(String errorcode, String description) {
49  this.errorcode = errorcode;
50  this.description = description;
51  }
52 
53  public String getCode() {
54  return errorcode;
55  }
56 
57  public String getDescription() {
58  return description;
59  }
60 
61  }
62 
64  super(errorCode.name());
65  this.errorCode = errorCode;
66  }
67 
68  public CTCloudException(CTCloudException.ErrorCode errorCode, Throwable throwable) {
69  super(errorCode.name(), throwable);
70  this.errorCode = errorCode;
71  }
72 
74  return errorCode;
75  }
76 
77  public String getErrorDetails() {
78  if(getErrorCode() == CTCloudException.ErrorCode.UNKNOWN && Objects.nonNull(getCause())){
79  return String.format("An API error %s occurred. Please try again, and contact Basis support at %s for help if the problem persists.",
80  StringUtils.isNotBlank(getCause().getLocalizedMessage()) ? "("+getCause().getLocalizedMessage()+")": "(Unknown)",
81  Constants.SUPPORT_AT_CYBERTRIAGE_DOT_COM );
82  }else {
83  return getErrorCode().getDescription();
84  }
85  }
86 
87  /*
88  * Attempts to find a more specific error code than "Unknown" for the given exception.
89  */
90  public static ErrorCode parseUnknownException(Throwable throwable) {
91 
92  String stackTrace = ExceptionUtils.getStackTrace(throwable);
93  if (stackTrace.contains("UnknownHostException")) {
94  return ErrorCode.UNKNOWN_HOST;
95  }
96 
97  return ErrorCode.UNKNOWN;
98  }
99 }
CTCloudException(CTCloudException.ErrorCode errorCode, Throwable throwable)
static ErrorCode parseUnknownException(Throwable throwable)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.