Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

Commit

Permalink
frontiers multiple catch blocks supported now
Browse files Browse the repository at this point in the history
  • Loading branch information
emjunior258 committed Oct 16, 2019
1 parent 57390fd commit 862c2d6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 111 deletions.
105 changes: 14 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,102 +5,25 @@ It's a light Java Framework that allows developers to write fully Ajax web appli
# Need some guidance?
Please read the documentation at [https://docs.hi-framework.org/1.1.0/getting-started/](https://docs.hi-framework.org/1.1.0/getting-started/index.html "Hi-Framework docs")

# 1.6.0 Changes
* New Security Configurations Introduced
* Content Expiration exception introduced
# 1.7.0 Changes
* Frontier calls new exceptions handling approach


## Content expiration event
## Frontier exceptions handling approach
Now you can handle specific exceptions in a very clean way.
See snippet below:

```javascript

Hi.template({
MyFrontier.something(param1,param2).try(function(){
//Successful call reaction comes here
}).catch("Exception1",function(ex){
//Some behavior here
}).catch("Exception2",function(ex){
//Some behavior here
}).catch(function(ex){
//Some behavior here;
});

...

$frontiers:{

...

//Handle content expiration exception
expired : function(call){
alert("Content expired");
}

...

}

...

});


```


## Security configurations

### Frontiers security configurations
See the __Hi.xml__ snippet below:
```xml

...

<frontiers>
<default-timeout>1600</default-timeout>
<security>
<cross-site-request-forgery>
<token>
<jwt-algorithm>HS512</jwt-algorithm>
<jwt-passphrase>4d1138af-18da-43fc-b4f5-e4bbebbc13d1</jwt-passphrase>
<secure-random-size>25</secure-random-size>
</token>
<cookie>
<secure>false</secure>
<http-only>true</http-only>
</cookie>
</cross-site-request-forgery>
</security>
</frontiers>

...

```

### General security configurations
See the __Hi.xml__ snippet below:
```xml

...

<security>
<content-security-policy>
<deny-iframe-embedding>true</deny-iframe-embedding>
<block-mixed-content>false</block-mixed-content>
<policy-allow>
<navigation to="http://myserver.com http://anotherserver.com *.facebook.com"/>
<!--default-src-->
<content from="'self'">
<!--img-src-->
<images from="'self' *.myserver.com"/>
<!--script-src-->
<scripts from="'self' *.myserver.com 'unsafe-inline' https://cdnjs.com"/>
<!--style-src-->
<styles from="'self' 'unsafe-inline'"/>
</content>
</policy-allow>
</content-security-policy>
</security>

...

```






The API will perform the redirect regardless of being invoked in the middle of an AJAX Request.
```
2 changes: 1 addition & 1 deletion Resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.emerjoin</groupId>
<artifactId>Hi-Framework-Resources</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<packaging>jar</packaging>

</project>
44 changes: 26 additions & 18 deletions Resources/src/main/resources/META-INF/resources/hi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,7 @@ Hi.$frontiers.Promise = function(){
var overequestCallback = undefined;
var catchCallback = undefined;
var finallyCallback = undefined;
var exceptionCallbacks = {};

var request = undefined;

Expand Down Expand Up @@ -2592,17 +2593,27 @@ Hi.$frontiers.Promise = function(){

};

this._setException = function(type){
this._setException = function(ex){

var gErrorHandler = getGlobalHandler("catch");
if(typeof ex != "number"){
var exceptionType = ex.type;
var exceptionDetails = ex.details;
if(exceptionCallbacks.hasOwnProperty(exceptionType)){
var callback = exceptionCallbacks[exceptionType];
callback.call(this,exceptionDetails);
this._setRequestFinished();
return;
}
}

var gErrorHandler = getGlobalHandler("catch");
if(typeof catchCallback=="function") {

catchCallback.call(this, type);
catchCallback.call(this, ex);

}else if(typeof gErrorHandler=="function") {

gErrorHandler.call(getGlobalHandlers(), this, type);
gErrorHandler.call(getGlobalHandlers(), this, ex);

}

Expand All @@ -2611,8 +2622,6 @@ Hi.$frontiers.Promise = function(){
};

//--public interface


this.try = function(obj) {


Expand Down Expand Up @@ -2699,14 +2708,15 @@ Hi.$frontiers.Promise = function(){

};

this.catch = function(callback){

if(typeof callback!="function")
this.catch = function(param1, param2){
if((typeof param1 == "string") && (typeof param2 == "function")){
exceptionCallbacks[param1] = param2;
}else if(typeof param1 == "function") {
catchCallback = param1;
}else{
throw new Error("Wrong parameters");

catchCallback = callback;
}
return this;

};

this.getRequest = function(){
Expand Down Expand Up @@ -3037,19 +3047,17 @@ var fMx = function(params,$functionUrl,_$tout,_$fmut,_$si,_$si_method,_$abpon,fa
var errorText = jqXml.responseText;
var exceptionType = undefined;

try {

try{
var responseJSON = JSON.parse(errorText);
if (responseJSON.hasOwnProperty("type") && responseJSON.hasOwnProperty("details")) {
promisse._setException(responseJSON);
return;
}

} catch (err) {

}catch(err){
console.error(err);
return;
}


//Request aborted
if (errText == "abort") {
promisse._setInterrupted();
Expand Down
2 changes: 1 addition & 1 deletion Resources/src/main/resources/META-INF/resources/hi.min.js

Large diffs are not rendered by default.

0 comments on commit 862c2d6

Please sign in to comment.