|
25 | 25 | import org.eclipse.ditto.json.JsonObject;
|
26 | 26 | import org.eclipse.ditto.json.JsonObjectBuilder;
|
27 | 27 | import org.eclipse.ditto.json.JsonPointer;
|
| 28 | +import org.eclipse.ditto.model.base.common.HttpStatusCode; |
28 | 29 | import org.eclipse.ditto.model.base.exceptions.DittoJsonException;
|
29 | 30 | import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException;
|
30 | 31 | import org.eclipse.ditto.model.base.headers.DittoHeaders;
|
31 | 32 | import org.eclipse.ditto.model.base.json.JsonSchemaVersion;
|
32 | 33 | import org.eclipse.ditto.signals.commands.base.AbstractCommandResponse;
|
| 34 | +import org.eclipse.ditto.signals.commands.base.CommandResponse; |
33 | 35 | import org.eclipse.ditto.signals.commands.base.ErrorResponse;
|
34 | 36 | import org.eclipse.ditto.signals.commands.things.exceptions.ThingErrorRegistry;
|
35 | 37 |
|
@@ -168,7 +170,23 @@ public static ThingErrorResponse fromJson(final ThingErrorRegistry thingErrorReg
|
168 | 170 | .build());
|
169 | 171 | final JsonObject payload = jsonObject.getValueOrThrow(ThingCommandResponse.JsonFields.PAYLOAD).asObject();
|
170 | 172 |
|
171 |
| - final DittoRuntimeException exception = thingErrorRegistry.parse(payload, dittoHeaders); |
| 173 | + DittoRuntimeException exception; |
| 174 | + try { |
| 175 | + exception = thingErrorRegistry.parse(payload, dittoHeaders); |
| 176 | + } catch (final Exception e) { |
| 177 | + final int status = jsonObject.getValue(CommandResponse.JsonFields.STATUS).orElse(500); |
| 178 | + final String errorCode = |
| 179 | + payload.getValue(DittoRuntimeException.JsonFields.ERROR_CODE).orElse("unknown:unknown"); |
| 180 | + final String errorMessage = |
| 181 | + payload.getValue(DittoRuntimeException.JsonFields.MESSAGE).orElse("An unknown error occurred"); |
| 182 | + final String errorDescription = payload.getValue(DittoRuntimeException.JsonFields.DESCRIPTION).orElse(""); |
| 183 | + exception = |
| 184 | + DittoRuntimeException.newBuilder(errorCode, |
| 185 | + HttpStatusCode.forInt(status).orElse(HttpStatusCode.INTERNAL_SERVER_ERROR)) |
| 186 | + .message(errorMessage) |
| 187 | + .description(errorDescription) |
| 188 | + .build(); |
| 189 | + } |
172 | 190 |
|
173 | 191 | return of(thingId, exception, dittoHeaders);
|
174 | 192 | }
|
|
0 commit comments