forked from opensearch-project/opensearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create ErrorStringResponse object and pass ErrorT type to the Si…
…mpleEndpoint request (opensearch-project#301) Signed-off-by: Dominik Szczepanczyk <[email protected]>
- Loading branch information
1 parent
89acf69
commit e79ce60
Showing
153 changed files
with
421 additions
and
186 deletions.
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
java-client/src/main/java/org/opensearch/client/opensearch/_types/ErrorStringResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
//---------------------------------------------------- | ||
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. | ||
//---------------------------------------------------- | ||
|
||
package org.opensearch.client.opensearch._types; | ||
|
||
import jakarta.json.stream.JsonGenerator; | ||
import org.opensearch.client.json.JsonpDeserializable; | ||
import org.opensearch.client.json.JsonpDeserializer; | ||
import org.opensearch.client.json.JsonpMapper; | ||
import org.opensearch.client.json.JsonpSerializable; | ||
import org.opensearch.client.json.ObjectBuilderDeserializer; | ||
import org.opensearch.client.json.ObjectDeserializer; | ||
import org.opensearch.client.util.ApiTypeHelper; | ||
import org.opensearch.client.util.ObjectBuilder; | ||
import org.opensearch.client.util.ObjectBuilderBase; | ||
|
||
import java.util.function.Function; | ||
|
||
// typedef: _types.ErrorSimpleResponseBase | ||
|
||
/** | ||
* The response returned by Elasticsearch when request execution did not | ||
* succeed. | ||
*/ | ||
@JsonpDeserializable | ||
public class ErrorStringResponse implements JsonpSerializable { | ||
private final String error; | ||
|
||
private final int status; | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
|
||
private ErrorStringResponse(Builder builder) { | ||
|
||
this.error = ApiTypeHelper.requireNonNull(builder.error, this, "error"); | ||
this.status = ApiTypeHelper.requireNonNull(builder.status, this, "status"); | ||
|
||
} | ||
|
||
public static ErrorStringResponse of(Function<Builder, ObjectBuilder<ErrorStringResponse>> fn) { | ||
return fn.apply(new Builder()).build(); | ||
} | ||
|
||
/** | ||
* Required - API name: {@code error} | ||
*/ | ||
public final String error() { | ||
return this.error; | ||
} | ||
|
||
/** | ||
* Required - API name: {@code status} | ||
*/ | ||
public final int status() { | ||
return this.status; | ||
} | ||
|
||
/** | ||
* Serialize this object to JSON. | ||
*/ | ||
public void serialize(JsonGenerator generator, JsonpMapper mapper) { | ||
generator.writeStartObject(); | ||
serializeInternal(generator, mapper); | ||
generator.writeEnd(); | ||
} | ||
|
||
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { | ||
|
||
generator.writeKey("error"); | ||
generator.write(this.error); | ||
|
||
generator.writeKey("status"); | ||
generator.write(this.status); | ||
|
||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* Builder for {@link ErrorStringResponse}. | ||
*/ | ||
|
||
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<ErrorStringResponse> { | ||
private String error; | ||
|
||
private Integer status; | ||
|
||
/** | ||
* Required - API name: {@code error} | ||
*/ | ||
public final Builder error(String value) { | ||
this.error = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* Required - API name: {@code error} | ||
*/ | ||
public final Builder error(Function<ErrorCause.Builder, ObjectBuilder<String>> fn) { | ||
return this.error(fn.apply(new ErrorCause.Builder()).build()); | ||
} | ||
|
||
/** | ||
* Required - API name: {@code status} | ||
*/ | ||
public final Builder status(int value) { | ||
this.status = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds a {@link ErrorStringResponse}. | ||
* | ||
* @throws NullPointerException if some of the required fields are null. | ||
*/ | ||
public ErrorStringResponse build() { | ||
_checkSingleUse(); | ||
|
||
return new ErrorStringResponse(this); | ||
} | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* Json deserializer for {@link ErrorStringResponse} | ||
*/ | ||
public static final JsonpDeserializer<ErrorStringResponse> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new, | ||
ErrorStringResponse::setupErrorResponseDeserializer); | ||
|
||
protected static void setupErrorResponseDeserializer(ObjectDeserializer<ErrorStringResponse.Builder> op) { | ||
|
||
op.add(Builder::error, JsonpDeserializer.stringDeserializer(), "error"); | ||
op.add(Builder::status, JsonpDeserializer.integerDeserializer(), "status"); | ||
|
||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...ent/src/main/java/org/opensearch/client/opensearch/_types/OpenSearchExceptionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.client.opensearch._types; | ||
|
||
public class OpenSearchExceptionFactory { | ||
|
||
private OpenSearchExceptionFactory() { | ||
//should be empty | ||
} | ||
|
||
public static <ErrorT> OpenSearchException createException(ErrorT error) { | ||
if (error instanceof ErrorResponse) { | ||
return new OpenSearchException((ErrorResponse) error); | ||
} else if (error instanceof ErrorStringResponse) { | ||
ErrorStringResponse errorStringResponse = (ErrorStringResponse) error; | ||
return new OpenSearchException(getErrorResponse(errorStringResponse.status(), "string_error", errorStringResponse.error())); | ||
} else { | ||
throw new OpenSearchException(getErrorResponse(500, "error_type", "Unknown error type: " + error.getClass())); | ||
} | ||
} | ||
|
||
private static ErrorResponse getErrorResponse(int status, String type, String reason) { | ||
return ErrorResponse.of( | ||
builder -> builder.status(status).error( | ||
builder1 -> builder1.type(type).reason(reason) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.