
001package org.hl7.fhir.dstu2.utils.client; 002 003/* 004 Copyright (c) 2011+, HL7, Inc. 005 All rights reserved. 006 007 Redistribution and use in source and binary forms, with or without modification, 008 are permitted provided that the following conditions are met: 009 010 * Redistributions of source code must retain the above copyright notice, this 011 list of conditions and the following disclaimer. 012 * Redistributions in binary form must reproduce the above copyright notice, 013 this list of conditions and the following disclaimer in the documentation 014 and/or other materials provided with the distribution. 015 * Neither the name of HL7 nor the names of its contributors may be used to 016 endorse or promote products derived from this software without specific 017 prior written permission. 018 019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 022 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 025 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 POSSIBILITY OF SUCH DAMAGE. 029 030*/ 031 032import java.util.ArrayList; 033import java.util.List; 034 035import org.hl7.fhir.dstu2.model.OperationOutcome; 036 037/** 038 * FHIR client exception. 039 * 040 * FHIR API exception will be wrapped in FHIR client exceptions. 041 * OperationOutcome errors resulting from the server can be access by calling: 042 * 043 * <pre> 044 * <code> 045 * if(e.hasServerErrors()) { 046 * List<OperationOutcome> errors = e.getServerErrors(); 047 * //process errors... 048 * } 049 * </code> 050 * </pre> 051 * 052 * 053 * 054 * @author Claude Nanjo 055 * 056 */ 057@Deprecated 058public class EFhirClientException extends RuntimeException { 059 private static final long serialVersionUID = 1L; 060 private List<OperationOutcome> errors = new ArrayList<OperationOutcome>(); 061 062 public EFhirClientException(String message) { 063 super(message); 064 } 065 066 public EFhirClientException(String message, List<OperationOutcome> serverErrors) { 067 super(message); 068 if (serverErrors != null && serverErrors.size() > 0) { 069 errors.addAll(serverErrors); 070 } 071 } 072 073 public EFhirClientException(Exception cause) { 074 super(cause); 075 } 076 077 public EFhirClientException(String message, Exception cause) { 078 super(message, cause); 079 } 080 081 /** 082 * Generate EFhirClientException which include a message indicating the cause of 083 * the exception along with any OperationOutcome server error that may have 084 * resulted. 085 * 086 * @param message 087 * @param serverError 088 */ 089 public EFhirClientException(String message, OperationOutcome serverError) { 090 super(message); 091 if (serverError != null) { 092 errors.add(serverError); 093 } 094 } 095 096 /** 097 * Generate EFhirClientException indicating the cause of the exception along 098 * with any OperationOutcome server error the server may have generated. 099 * 100 * A default message of "One or more server side errors have occurred during 101 * this operation. Refer to e.getServerErrors() for additional details." will be 102 * returned to users. 103 * 104 * @param message 105 * @param serverError 106 */ 107 public EFhirClientException(OperationOutcome serverError) { 108 super("Error on the server: " + serverError.getText().getDiv().allText() 109 + ". Refer to e.getServerErrors() for additional details."); 110 if (serverError != null) { 111 errors.add(serverError); 112 } 113 } 114 115 /** 116 * Method returns all OperationOutcome server errors that are associated with 117 * this exception. 118 * 119 * @return 120 */ 121 public List<OperationOutcome> getServerErrors() { 122 return errors; 123 } 124 125 /** 126 * Method returns true if exception contains server OperationOutcome errors in 127 * payload. 128 * 129 * @return 130 */ 131 public boolean hasServerErrors() { 132 return errors.size() > 0; 133 } 134 135}