4848import org .exist .Namespaces ;
4949import org .exist .dom .QName ;
5050
51+ import javax .annotation .Nullable ;
52+
5153/**
5254 *
5355 * @author aretter
@@ -295,14 +297,14 @@ public class ErrorCodes {
295297 public static class ErrorCode {
296298
297299 private final QName errorQName ;
298- private final String description ;
300+ private @ Nullable final String description ;
299301
300- public ErrorCode (String code , String description ) {
302+ public ErrorCode (final String code , @ Nullable final String description ) {
301303 this .errorQName = new QName (code , Namespaces .EXIST_XQUERY_XPATH_ERROR_NS , Namespaces .EXIST_XQUERY_XPATH_ERROR_PREFIX );
302304 this .description = description ;
303305 }
304306
305- public ErrorCode (QName errorQName , String description ) {
307+ public ErrorCode (final QName errorQName , final String description ) {
306308 this .errorQName = errorQName ;
307309 this .description = description ;
308310 }
@@ -313,10 +315,10 @@ public QName getErrorQName() {
313315
314316 @ Override
315317 public String toString () {
316- return "(" + errorQName .getNamespaceURI () + "#" + errorQName . getLocalPart () + "): " + description ;
318+ return "(" + errorQName .toString () + "): " + description ;
317319 }
318320
319- public String getDescription (){
321+ public @ Nullable String getDescription (){
320322 return description ;
321323 }
322324 }
@@ -337,12 +339,21 @@ private EXistErrorCode(String code, String description) {
337339
338340 public static class JavaErrorCode extends ErrorCode {
339341
340- public JavaErrorCode (final Throwable throwable ) {
341- super (new QName (
342- throwable .getClass ().getName (),
343- Namespaces .EXIST_JAVA_BINDING_NS ,
344- Namespaces .EXIST_JAVA_BINDING_NS_PREFIX ),
345- throwable .getMessage () != null ? throwable .getMessage () : throwable .getCause ().getMessage ());
342+ private JavaErrorCode (final QName errorQName , @ Nullable final String description ) {
343+ super (errorQName , description );
344+ }
345+
346+ public static JavaErrorCode fromThrowable (final Throwable throwable ) {
347+ final QName errorQName = new QName (throwable .getClass ().getName (), Namespaces .EXIST_JAVA_BINDING_NS , Namespaces .EXIST_JAVA_BINDING_NS_PREFIX );
348+ @ Nullable final String description ;
349+ if (throwable .getMessage () != null ) {
350+ description = throwable .getMessage ();
351+ } else if (throwable .getCause () != null ) {
352+ description = throwable .getCause ().getMessage ();
353+ } else {
354+ description = null ;
355+ }
356+ return new JavaErrorCode (errorQName , description );
346357 }
347358 }
348359}
0 commit comments