/** * Given a {@link JsonArray} representing a {@link Set} of {@link ErrorModel}, it will deserialize them. * Also contribute with the given {@link this#errorModelRespository}. * * @param errors The json array * @return The a {@link Map} with the Error Identifier as key and the represented {@link ErrorModel} */ Map<String, ErrorModel> parseErrors(JsonArray errors) { Map<String, Pair<String, ErrorModelBuilder>> buildingErrors = new LinkedHashMap<>(); errors.iterator().forEachRemaining(element -> { JsonObject error = element.getAsJsonObject(); String anError = error.get(ERROR).getAsString(); String parentError = EMPTY; if (error.has(PARENT)) { parentError = error.get(PARENT).getAsString(); } ErrorModelBuilder errorModelBuilder = newError(buildFromStringRepresentation(anError)); if (error.has(HANDLEABLE)) { errorModelBuilder.handleable(error.get(HANDLEABLE).getAsBoolean()); } buildingErrors.put(anError, new Pair<>(parentError, errorModelBuilder)); }); buildingErrors.keySet().forEach(key -> buildError(key, buildingErrors, errorModelRespository)); return errorModelRespository; }
private void declareErrors(ExtensionDeclarer extensionDeclarer) { final ErrorModel criticalError = newError(CRITICAL).handleable(false).build(); final ErrorModel overloadError = newError(OVERLOAD).withParent(criticalError).build(); final ErrorModel securityError = newError(SECURITY).withParent(anyError).build(); extensionDeclarer.withErrorModel(newError(STREAM_MAXIMUM_SIZE_EXCEEDED).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(TIMEOUT).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(UNKNOWN).handleable(false).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_GENERATE).handleable(false).withParent(sourceError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_SEND).handleable(false).withParent(sourceError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_GENERATE).withParent(sourceResponseError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_SEND).handleable(false).withParent(sourceResponseError).build()); extensionDeclarer.withErrorModel(newError(FLOW_BACK_PRESSURE).handleable(false).withParent(overloadError).build()); extensionDeclarer.withErrorModel(newError(FATAL).handleable(false).withParent(criticalError).build());