Skip to content

Commit

Permalink
RMET-2343 Social Logins Plugin - Update error codes (#39)
Browse files Browse the repository at this point in the history
* feat: format error codes

References: https://outsystemsrd.atlassian.net/browse/RMET-2343

* chore: update changelog

* fix: fixing typo on error message

---------

Co-authored-by: Marta Carlos <marta.carlos@outsystems.com>
  • Loading branch information
alexgerardojacinto and OS-martacarlos committed Jan 23, 2024
1 parent f41e55f commit b70a06f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

## 2023-03-20
- Feat: Update error code format
- Feat: [Android] Update error codes and descriptions (https://outsystemsrd.atlassian.net/browse/RMET-2343)

### 2023-03-16
- Feat: [iOS] Update error codes and descriptions (https://outsystemsrd.atlassian.net/browse/RMET-2342).

Expand Down
2 changes: 1 addition & 1 deletion hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
} else throw new Error("Bad Request: make sure your apps is configured correctly")
}
if(err.response.status == 404){
throw new Error("Not found: Social Logins Configurator is either outdated or CONFIGURATOR_BASE_URL is not well defined.");
throw new Error("Not found: Social Logins Configurator is either outdated or SOCIAL_CONF_API_ENDPOINT is not well defined.");
}
} else if(err.request){
throw new Error("Something went wrong with the request. " + err.toJSON());
Expand Down
22 changes: 15 additions & 7 deletions src/android/com/outsystems/plugins/sociallogins/OSSocialLogins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ class OSSocialLogins : CordovaImplementation() {
private var linkedinController: SocialLoginsLinkedinController? = null
private var facebookController: SocialLoginsFacebookController? = null

companion object {
private const val ERROR_FORMAT_PREFIX = "OS-PLUG-SOCI-"
}

private var delegate = object : SocialLoginsInterface {
override fun callbackError(error: SocialLoginError) {
sendPluginResult(null, Pair(error.code.toString(), error.message))
sendPluginResult(null, Pair(formatErrorCode(error.code), error.message))
}
override fun callbackUserInfo(result: UserInfo) {
val pluginResponseJson = gson.toJson(result)
Expand Down Expand Up @@ -115,16 +119,16 @@ class OSSocialLogins : CordovaImplementation() {
redirectUri = args.get(2).toString()

if(clientId.isNullOrEmpty() || redirectUri.isNullOrEmpty()){
sendPluginResult(null, Pair(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code.toString(), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
sendPluginResult(null, Pair(formatErrorCode(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
}
else{
setAsActivityResultCallback()
socialLoginController?.doLoginLinkedin(state, clientId, redirectUri, cordova.activity)
}
}catch (e: JSONException){
sendPluginResult(null, Pair(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code.toString(), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
sendPluginResult(null, Pair(formatErrorCode(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
}catch (e: Exception){
sendPluginResult(null, Pair(SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.code.toString(), SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.message))
sendPluginResult(null, Pair(formatErrorCode(SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.code), SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.message))
}

}
Expand All @@ -140,16 +144,16 @@ class OSSocialLogins : CordovaImplementation() {
redirectUri = args.get(2).toString()

if(clientId.isNullOrEmpty() || redirectUri.isNullOrEmpty()){
sendPluginResult(null, Pair(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code.toString(), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
sendPluginResult(null, Pair(formatErrorCode(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
}
else{
setAsActivityResultCallback()
socialLoginController?.doLoginApple(state, clientId, redirectUri, cordova.activity)
}
}catch (e: JSONException){
sendPluginResult(null, Pair(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code.toString(), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
sendPluginResult(null, Pair(formatErrorCode(SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.code), SocialLoginError.MISSING_INPUT_PARAMETERS_ERROR.message))
}catch (e: Exception){
sendPluginResult(null, Pair(SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.code.toString(), SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.message))
sendPluginResult(null, Pair(formatErrorCode(SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.code), SocialLoginError.APPLE_SIGN_IN_GENERAL_ERROR.message))
}

}
Expand All @@ -171,4 +175,8 @@ class OSSocialLogins : CordovaImplementation() {
return true
}

private fun formatErrorCode(code: Int): String {
return ERROR_FORMAT_PREFIX + code.toString().padStart(4, '0')
}

}

0 comments on commit b70a06f

Please sign in to comment.