/** * 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()); }