mirror of
https://github.com/OpenBankProject/API-Explorer.git
synced 2026-02-06 18:56:49 +00:00
Merge pull request #222 from hongwei1/develop
feature/enhanced the error handling
This commit is contained in:
commit
2ca0e1954c
35
README.md
35
README.md
@ -74,7 +74,7 @@ Note: You may need to add the pluginGroup to the $HOME/.m2/settings.xml
|
||||
|
||||
* Navigate to test/scala/RunWebApp. You may see a Setup Scala SDK link. Click this and check Scala 2.11.8 or so.
|
||||
|
||||
* In src/main/resources/props create a \<yourloginname\>.props (or default.props) for development. For localhost set api_hostname=http://127.0.0.1:8080, defaultAuthProvider=http://127.0.0.1:8080, base_url=http://localhost:8082, dev.port=8082 and oauth keys (i.e. obp_consumer_key and obp_consumer_secret) obtained from the api (at /consumer-registration) to run [OBP-API](https://github.com/OpenBankProject/OBP-API) in your local environment.
|
||||
* In src/main/resources/props create a \<yourloginname\>.props (or default.props) for development. For localhost set api_hostname=http://127.0.0.1:8080, base_url=http://localhost:8082, dev.port=8082 and oauth keys (i.e. obp_consumer_key and obp_consumer_secret) obtained from the api (at /consumer-registration) to run [OBP-API](https://github.com/OpenBankProject/OBP-API) in your local environment.
|
||||
|
||||
* Now **Rebuild** the project so everything is compiled. At this point you may need to select the SDK, see above.
|
||||
|
||||
@ -124,13 +124,36 @@ The keys are obtained by registering as a developer on the Open Bank Project API
|
||||
|
||||
All in all, a props file could look something like:
|
||||
|
||||
api_hostname=https://api.openbankproject.com/api \
|
||||
defaultAuthProvider=https://api.openbankproject.com/api
|
||||
api_hostname=https://api.openbankproject.com/api
|
||||
|
||||
### OR
|
||||
The base url of the api to use for local: \
|
||||
api_hostname=http://127.0.0.1:8080 \
|
||||
defaultAuthProvider=http://127.0.0.1:8080
|
||||
The base url of the api to use for local:
|
||||
api_hostname=http://127.0.0.1:8080
|
||||
|
||||
obp_consumer_key=uodsifnodsfifdsliufdsliufdsfdsfsdfsx \
|
||||
obp_secret_key=iuesbfiyvglxzgifg7eisgei7fglesfi \
|
||||
base_url=http://localhost:8082
|
||||
|
||||
## The list of Endpoints that API Explorer needs to function
|
||||
|
||||
### Before Login:
|
||||
Get API Info (root): /obp/v4.0.0/root \
|
||||
Get Banks: /obp/v3.1.0/banks \
|
||||
Get Resource Docs: /obp/v4.0.0/resource-docs/OBPv5.1.0/obp \
|
||||
Get Glossary of the API: /obp/v3.0.0/api/glossary \
|
||||
Get all Authentication Type Validations - public: /obp/v4.0.0/endpoints/authentication-type-validations \
|
||||
Get all JSON Schema Validations: /obp/v4.0.0/endpoints/json-schema-validations \
|
||||
Get Message Docs: /obp/v2.2.0/message-docs/CONNECTOR
|
||||
|
||||
### After Login
|
||||
Oauth1.0: /oauth/initiate \
|
||||
Oauth1.0: /oauth/token
|
||||
|
||||
Get private accounts at all banks (Authenticated access): /obp/v1.2.1/accounts/private \
|
||||
Get Entitlements for the current User: /obp/v3.0.0/my/entitlements \
|
||||
Get Entitlement Requests for the current User: /obp/v3.0.0/my/entitlement-requests \
|
||||
Get My Spaces: /obp/v4.0.0/my/spaces \
|
||||
Get Api Collection Endpoints: /obp/v4.0.0/api-collections//api-collection-endpoints \
|
||||
Get My Api Collection Endpoints: /obp/v4.0.0/my/api-collections/Favourites/api-collection-endpoints \
|
||||
Get My Api Collections: /obp/v4.0.0/my/api-collections \
|
||||
Get User (Current): /obp/v3.0.0/users/current
|
||||
@ -8,9 +8,6 @@
|
||||
# The base url of the api to use (e.g. https://apisandbox.openbankproject.com)
|
||||
api_hostname=FILL_ME_IN
|
||||
|
||||
# For now, this value should be identical to the value of api_hostname
|
||||
defaultAuthProvider=FILL_ME_IN
|
||||
|
||||
# These are the oauth keys obtained from the api (at /consumer-registration)
|
||||
obp_consumer_key=FILL_ME_IN
|
||||
obp_secret_key=FILL_ME_IN
|
||||
|
||||
@ -166,10 +166,6 @@ class Boot extends MdcLoggable{
|
||||
firstChoicePropsDir.toList.flatten ::: secondChoicePropsDir.toList.flatten
|
||||
}
|
||||
|
||||
if(Helper.getPropsValue("defaultAuthProvider").isEmpty) {
|
||||
throw new Exception("defaultAuthProvider must be specified in the props file!")
|
||||
}
|
||||
|
||||
def check(bool: Boolean) : Box[LiftResponse] = {
|
||||
if(bool){
|
||||
Empty
|
||||
|
||||
@ -189,10 +189,20 @@ object OAuthClient extends MdcLoggable {
|
||||
logger.debug("redirect says: credential.provider: " + credential.provider)
|
||||
logger.debug("redirect says: oauthcallbackUrl: " + oauthcallbackUrl)
|
||||
credential.consumer.setMessageSigner(new HmacSha256MessageSigner())
|
||||
val authUrl = provider.oAuthProvider.retrieveRequestToken(credential.consumer, oauthcallbackUrl)
|
||||
logger.debug("redirect says: authUrl: " + authUrl)
|
||||
val authUrlBox = tryo {provider.oAuthProvider.retrieveRequestToken(credential.consumer, oauthcallbackUrl)}
|
||||
|
||||
if(authUrlBox.isInstanceOf[Failure]) {
|
||||
val errorMessage = "Critical exception happened on the backend: " + authUrlBox.asInstanceOf[Failure].messageChain
|
||||
logger.error(errorMessage)
|
||||
throw new Exception(errorMessage)
|
||||
} else if(authUrlBox.isEmpty){
|
||||
logger.error("Critical exception happened on backend: oauth callback Url is empty! Please check the consumer key and secret first.")
|
||||
throw new Exception("Critical exception happened on backend: oauth callback Url is empty! Please check the consumer key and secret first.")
|
||||
} else{
|
||||
logger.debug("redirect says: authUrlBox: " + authUrlBox.head)
|
||||
S.redirectTo(authUrlBox.head)
|
||||
}
|
||||
|
||||
S.redirectTo(authUrl)
|
||||
}
|
||||
|
||||
def redirectToConnectBankAccount() = {
|
||||
|
||||
@ -46,8 +46,6 @@ object ObpAPI extends Loggable {
|
||||
implicit val formats = DefaultFormats
|
||||
val dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
|
||||
|
||||
val defaultProvider = Helper.getPropsValue("defaultAuthProvider").getOrElse("")
|
||||
|
||||
val userNotFoundError = "user (\\S+) at provider (\\S+) not found".r
|
||||
|
||||
final val AccountUrlPath = "/accounts/"
|
||||
|
||||
@ -1046,7 +1046,7 @@ WIP to add comments on resource docs. This code copied from Sofit.
|
||||
val jsEnabledBtn = s"jQuery('input[name=$name]').removeAttr('disabled')"
|
||||
//We call the getApiCollectionsForCurrentUser endpoint again, to make sure we already created or delete the record there.
|
||||
val apiFavouriteCollection = ObpAPI.getApiCollection("Favourites")
|
||||
val errorMessage = if(apiFavouriteCollection.isInstanceOf[Failure]) apiFavouriteCollection.asInstanceOf[Failure].messageChain else ""
|
||||
val errorMessage = if(apiFavouriteCollection.isInstanceOf[Failure]) "Error happened on backend: "+apiFavouriteCollection.asInstanceOf[Failure].messageChain else ""
|
||||
|
||||
|
||||
if(apiFavouriteCollection.isInstanceOf[Failure]){ // If the user is not logged in, we do not need call any apis calls. (performance enhancement)
|
||||
@ -1060,7 +1060,7 @@ WIP to add comments on resource docs. This code copied from Sofit.
|
||||
}else{
|
||||
if (myWebpageOperationIds.contains(favouritesOperationIdFromWebpage)) { //If we already have this operationId, we need to delete it
|
||||
val deletedBox = ObpAPI.deleteMyApiCollectionEndpoint("Favourites",favouritesOperationIdFromWebpage)
|
||||
val deleteErrorMessage = if(deletedBox.isInstanceOf[Failure]) deletedBox.asInstanceOf[Failure].messageChain else ""
|
||||
val deleteErrorMessage = if(deletedBox.isInstanceOf[Failure]) "Error happened on backend: "+ deletedBox.asInstanceOf[Failure].messageChain else ""
|
||||
if (deletedBox.isInstanceOf[Failure]){
|
||||
SetHtml(s"favourites_error_message_${favouritesOperationIdFromWebpage}", Text(deleteErrorMessage)) &
|
||||
Run(jsEnabledBtn)
|
||||
@ -1069,7 +1069,7 @@ WIP to add comments on resource docs. This code copied from Sofit.
|
||||
}
|
||||
} else {//If we do not have this operationId, we need to create it.
|
||||
val createdBox = ObpAPI.createMyApiCollectionEndpoint("Favourites",favouritesOperationIdFromWebpage)
|
||||
val createdErrorMessage = if(createdBox.isInstanceOf[Failure]) createdBox.asInstanceOf[Failure].messageChain else ""
|
||||
val createdErrorMessage = if(createdBox.isInstanceOf[Failure]) "Error happened on backend: "+ createdBox.asInstanceOf[Failure].messageChain else ""
|
||||
if (createdBox.isInstanceOf[Failure]){
|
||||
SetHtml(s"favourites_error_message_${favouritesOperationIdFromWebpage}", Text(createdErrorMessage)) &
|
||||
Run(jsEnabledBtn)
|
||||
@ -1565,7 +1565,7 @@ WIP to add comments on resource docs. This code copied from Sofit.
|
||||
ResourceStyleCss #> s"${DisplayEqualNone}" &
|
||||
ResourceErrorStyleCss #> s"${DisplayEqualBlock}" &
|
||||
ContentBoxHeadline #> {
|
||||
allResourcesBox.asInstanceOf[Failure].msg
|
||||
"Error happened on backend: "+allResourcesBox.asInstanceOf[Failure].msg
|
||||
}&
|
||||
{
|
||||
if(allResourcesBox.asInstanceOf[Failure].msg.contains("CanReadResourceDoc")){
|
||||
|
||||
@ -35,10 +35,10 @@ package code.snippet
|
||||
import net.liftweb.http.js.JsCmd
|
||||
import net.liftweb.util.Helpers
|
||||
import Helpers._
|
||||
import net.liftweb.http.SHtml
|
||||
import net.liftweb.http.{ResponseShortcutException, SHtml}
|
||||
import code.lib.{OAuthClient, ObpAPI}
|
||||
import net.liftweb.common.Box
|
||||
import net.liftweb.http.js.JsCmds.Noop
|
||||
import net.liftweb.http.js.JsCmds.{Alert, Noop}
|
||||
|
||||
class Login {
|
||||
private def getDisplayNameOfUser(): Box[String] = {
|
||||
@ -69,8 +69,17 @@ class Login {
|
||||
".logged-in *" #> "" &
|
||||
"#start-login [onclick]" #> {
|
||||
def actionJS: JsCmd = {
|
||||
OAuthClient.redirectToOauthLogin()
|
||||
Noop
|
||||
try {
|
||||
OAuthClient.redirectToOauthLogin()
|
||||
}
|
||||
catch {
|
||||
//this is the Liftweb redirect mechanism, it will throw the ResponseShortcutException.
|
||||
case e: ResponseShortcutException =>
|
||||
OAuthClient.redirectToOauthLogin()
|
||||
Noop
|
||||
case e: Throwable =>
|
||||
Alert(e.getMessage)
|
||||
}
|
||||
}
|
||||
SHtml.onEvent((s: String) => actionJS)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user