* @return created ODataErrorContext based on input stream content.
* @throws EntityProviderException if an exception during read / deserialization occurs.
*/
public ODataErrorContext readError(final InputStream errorDocument) throws EntityProviderException {
XMLStreamReader reader = null;
EntityProviderException cachedException = null;
try {
reader = XmlHelper.createStreamReader(errorDocument);
return parserError(reader);
} catch (XMLStreamException e) {
cachedException = new EntityProviderException(EntityProviderException.INVALID_STATE.addContent(
e.getMessage()), e);
throw cachedException;
} catch (EntityProviderException e) {
cachedException = e;
throw cachedException;
} finally {// NOPMD (suppress DoNotThrowExceptionInFinally)
if (reader != null) {
try {
reader.close();
} catch (XMLStreamException e) {
if (cachedException != null) {
throw cachedException;
} else {
throw new EntityProviderException(
EntityProviderException.EXCEPTION_OCCURRED.addContent(
e.getClass().getSimpleName()), e);
}
}
}