Search in sources :

Example 1 with SingleError

use of com.helger.commons.error.SingleError in project phive by phax.

the class PhiveJsonHelper method getAsIError.

@Nonnull
public static IError getAsIError(@Nonnull final IJsonObject aObj) {
    final IErrorLevel aErrorLevel = getAsErrorLevel(aObj.getAsString(JSON_ERROR_LEVEL));
    final String sErrorID = aObj.getAsString(JSON_ERROR_ID);
    final String sErrorFieldName = aObj.getAsString(JSON_ERROR_FIELD_NAME);
    // Try new structured version
    ILocation aErrorLocation = getAsErrorLocation(aObj.getAsObject(JSON_ERROR_LOCATION_OBJ));
    if (aErrorLocation == null) {
        final IJsonValue aErrorLocationValue = aObj.getAsValue(JSON_ERROR_LOCATION_STR);
        if (aErrorLocationValue != null) {
            // It's a string - old version
            aErrorLocation = new SimpleLocation(aErrorLocationValue.getAsString());
        }
    }
    final String sErrorText = aObj.getAsString(JSON_ERROR_TEXT);
    final String sTest = aObj.getAsString(JSON_TEST);
    final PhiveRestoredException aLinkedException = PhiveRestoredException.createFromJson(aObj.getAsObject(JSON_EXCEPTION));
    if (sTest != null)
        return new SVRLResourceError(aErrorLevel, sErrorID, sErrorFieldName, aErrorLocation, new ConstantHasErrorText(sErrorText), aLinkedException, sTest);
    return new SingleError(aErrorLevel, sErrorID, sErrorFieldName, aErrorLocation, new ConstantHasErrorText(sErrorText), aLinkedException);
}
Also used : IJsonValue(com.helger.json.IJsonValue) SingleError(com.helger.commons.error.SingleError) ILocation(com.helger.commons.location.ILocation) IErrorLevel(com.helger.commons.error.level.IErrorLevel) SimpleLocation(com.helger.commons.location.SimpleLocation) SVRLResourceError(com.helger.schematron.svrl.SVRLResourceError) ConstantHasErrorText(com.helger.commons.error.text.ConstantHasErrorText) Nonnull(javax.annotation.Nonnull)

Aggregations

SingleError (com.helger.commons.error.SingleError)1 IErrorLevel (com.helger.commons.error.level.IErrorLevel)1 ConstantHasErrorText (com.helger.commons.error.text.ConstantHasErrorText)1 ILocation (com.helger.commons.location.ILocation)1 SimpleLocation (com.helger.commons.location.SimpleLocation)1 IJsonValue (com.helger.json.IJsonValue)1 SVRLResourceError (com.helger.schematron.svrl.SVRLResourceError)1 Nonnull (javax.annotation.Nonnull)1