/** * Constructs a new {@code AbstractErrorRegistry} for the specified {@code parseStrategies}. * * @param parseStrategies the parse strategies. * @param fallbackErrorRegistry the {@link ErrorRegistry} to be used as fallback * @throws NullPointerException if any argument is {@code null}. */ protected AbstractErrorRegistry(final Map<String, JsonParsable<T>> parseStrategies, final ErrorRegistry<T> fallbackErrorRegistry) { super(mergeParseRegistries(parseStrategies, fallbackErrorRegistry)); }
/** * Creates a {@code ThingErrorResponse} from the given {@code adaptable}. * * @param adaptable the adaptable to convert. * @return the ThingErrorResponse. */ private ThingErrorResponse thingErrorResponseFromAdaptable(final Adaptable adaptable) { final DittoHeaders dittoHeaders = headerTranslator.fromExternalHeaders(adaptable.getHeaders().orElse(DittoHeaders.empty())); final TopicPath topicPath = adaptable.getTopicPath(); final DittoRuntimeException dittoRuntimeException = adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(jsonObject -> { try { return errorRegistry.parse(jsonObject, dittoHeaders); } catch (final JsonTypeNotParsableException e) { return DittoRuntimeException.fromUnknownErrorJson(jsonObject, dittoHeaders) .orElseThrow(() -> e); } }) .orElseThrow(() -> new JsonMissingFieldException(ThingCommandResponse.JsonFields.PAYLOAD)); final String thingId = topicPath.getNamespace() + ":" + topicPath.getId(); return ThingErrorResponse.of(thingId, dittoRuntimeException, dittoRuntimeException.getDittoHeaders()); }
/** * Creates a {@code ThingErrorResponse} from the given {@code adaptable}. * * @param adaptable the adaptable to convert. * @return the ThingErrorResponse. */ private ThingErrorResponse thingErrorResponseFromAdaptable(final Adaptable adaptable) { final DittoHeaders dittoHeaders = headerTranslator.fromExternalHeaders(adaptable.getHeaders().orElse(DittoHeaders.empty())); final TopicPath topicPath = adaptable.getTopicPath(); final DittoRuntimeException dittoRuntimeException = adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(jsonObject -> { try { return errorRegistry.parse(jsonObject, dittoHeaders); } catch (final JsonTypeNotParsableException e) { return DittoRuntimeException.fromUnknownErrorJson(jsonObject, dittoHeaders) .orElseThrow(() -> e); } }) .orElseThrow(() -> new JsonMissingFieldException(ThingCommandResponse.JsonFields.PAYLOAD)); final String thingId = topicPath.getNamespace() + ":" + topicPath.getId(); return ThingErrorResponse.of(thingId, dittoRuntimeException, dittoRuntimeException.getDittoHeaders()); }
/** * Constructs a new {@code AbstractErrorRegistry} for the specified {@code parseStrategies}. * * @param parseStrategies the parse strategies. * @param fallbackErrorRegistry the {@link ErrorRegistry} to be used as fallback * @throws NullPointerException if any argument is {@code null}. */ protected AbstractErrorRegistry(final Map<String, JsonParsable<T>> parseStrategies, final ErrorRegistry<T> fallbackErrorRegistry) { super(mergeParseRegistries(parseStrategies, fallbackErrorRegistry)); }