Class ConnectorResponse
- java.lang.Object
-
- com.snowflake.connectors.common.response.ConnectorResponse
-
public class ConnectorResponse extends Object
A standard response format used by the connectors sdk, consisting of a response code, a message, and a custom additional payload.The message is optional in case of a successful response, otherwise it is obligatory.
-
-
Constructor Summary
Constructors Constructor Description ConnectorResponse(String responseCode, String message)
Creates a newConnectorResponse
, with the provided response code, message, and no additional response payload.ConnectorResponse(String responseCode, String message, Map<String,Variant> additionalPayload)
Creates a newConnectorResponse
, with the provided response code, message, and additional response payload.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
static ConnectorResponse
error(String errorCode, String errorMessage)
Creates a new error response instance, with provided response code, message, and no additional payload.static ConnectorResponse
error(String errorCode, String errorMessage, Map<String,Variant> additionalPayload)
Creates a new error response instance, with provided response code, message, and additional payload.static ConnectorResponse
fromException(String exceptionBody)
Creates a new error response instance by parsing the provided exception body.static ConnectorResponse
fromVariant(Variant variant)
Creates a new error response instance from the provided Variant.Map<String,Variant>
getAdditionalPayload()
Returns the additional response payload.String
getMessage()
Returns the response message.String
getResponseCode()
Returns the response code.int
hashCode()
boolean
is(String code)
Returns whether the code of this response is equal to the provided code.boolean
isNotOk()
Returns whether the code of this response is not equal toOK
.boolean
isOk()
Returns whether the code of this response is equal toOK
.static ConnectorResponse
success()
Creates a new connector response instance, with response code ofOK
, no message, and no additional payload.static ConnectorResponse
success(String message)
Creates a new response instance, with response code ofOK
, provided message, and no additional payload.static ConnectorResponse
success(String message, Map<String,Variant> additionalPayload)
Creates a new response instance, with response code ofOK
, provided message, and additional payload.String
toJson()
Returns the properties of this response in a JSON String.Map<String,Variant>
toMap()
Returns the properties of this response in a Map.Variant
toVariant()
Returns the properties of this response in a Variant.Variant
toVariant(Variant baseVariant)
Returns the properties of this response appended to the provided Variant.ConnectorResponse
withAdditionalPayload(String key, Variant value)
Adds a new key-value pair to additional payload
-
-
-
Constructor Detail
-
ConnectorResponse
public ConnectorResponse(String responseCode, String message)
Creates a newConnectorResponse
, with the provided response code, message, and no additional response payload.- Parameters:
responseCode
- response codemessage
- response message
-
ConnectorResponse
public ConnectorResponse(String responseCode, String message, Map<String,Variant> additionalPayload)
Creates a newConnectorResponse
, with the provided response code, message, and additional response payload.- Parameters:
responseCode
- response codemessage
- response messageadditionalPayload
- additional response payload
-
-
Method Detail
-
success
public static ConnectorResponse success()
Creates a new connector response instance, with response code ofOK
, no message, and no additional payload.- Returns:
- new successful connector response instance
-
success
public static ConnectorResponse success(String message)
Creates a new response instance, with response code ofOK
, provided message, and no additional payload.- Parameters:
message
- response message- Returns:
- new successful response instance
-
success
public static ConnectorResponse success(String message, Map<String,Variant> additionalPayload)
Creates a new response instance, with response code ofOK
, provided message, and additional payload.- Parameters:
message
- response messageadditionalPayload
- additional response payload- Returns:
- new successful response instance
-
error
public static ConnectorResponse error(String errorCode, String errorMessage)
Creates a new error response instance, with provided response code, message, and no additional payload.- Parameters:
errorCode
- response codeerrorMessage
- response message- Returns:
- new error response instance
-
error
public static ConnectorResponse error(String errorCode, String errorMessage, Map<String,Variant> additionalPayload)
Creates a new error response instance, with provided response code, message, and additional payload.- Parameters:
errorCode
- response codeerrorMessage
- response messageadditionalPayload
- additional response payload- Returns:
- new error response instance
-
fromException
public static ConnectorResponse fromException(String exceptionBody)
Creates a new error response instance by parsing the provided exception body.Provided exception body must be a valid connector response, written as a JSON String.
- Parameters:
exceptionBody
- exception body- Returns:
- new error response instance
- Throws:
InvalidConnectorResponseException
- if the provided String is not a valid response JSON String
-
fromVariant
public static ConnectorResponse fromVariant(Variant variant)
Creates a new error response instance from the provided Variant.Provided Variant must be a valid connector response, containing all the necessary properties.
- Parameters:
variant
- variant with the response- Returns:
- new error response instance
- Throws:
InvalidConnectorResponseException
- if the provided Variant is not a valid response
-
getResponseCode
public String getResponseCode()
Returns the response code.- Returns:
- response code
-
getMessage
public String getMessage()
Returns the response message.- Returns:
- response message
-
getAdditionalPayload
public Map<String,Variant> getAdditionalPayload()
Returns the additional response payload.- Returns:
- additional response payload
-
withAdditionalPayload
public ConnectorResponse withAdditionalPayload(String key, Variant value)
Adds a new key-value pair to additional payload- Returns:
- this ConnectorResponse instance
-
toMap
public Map<String,Variant> toMap()
Returns the properties of this response in a Map.- Returns:
- properties of this response in a Map
-
toVariant
public Variant toVariant()
Returns the properties of this response in a Variant.- Returns:
- properties of this response in a Variant
-
toVariant
public Variant toVariant(Variant baseVariant)
Returns the properties of this response appended to the provided Variant.- Parameters:
baseVariant
- base Variant to which the properties of this response should be appended- Returns:
- properties of this response appended to the provided Variant
-
toJson
public String toJson()
Returns the properties of this response in a JSON String.- Returns:
- properties of this response in a JSON String
-
is
public boolean is(String code)
Returns whether the code of this response is equal to the provided code.- Parameters:
code
- response code- Returns:
- whether the code of this response is equal to the provided code
-
isOk
public boolean isOk()
Returns whether the code of this response is equal toOK
.- Returns:
- whether the code of this response is equal to
OK
-
isNotOk
public boolean isNotOk()
Returns whether the code of this response is not equal toOK
.- Returns:
- whether the code of this response is not equal to
OK
-
-