mercredi 1 novembre 2017

Store error variable

I am approaching this from a OO background so my approach is wrong!

What I am doing is when I get an error I am trying to store the error for retrieval by error(40x,50x) pages so they can display. Below is the simple JS class I wrote:

var errorMessage="unknown";

function setMessage(error){

    errorMessage=error;
    console.log("Setting: "+errorMessage);

}

function getMessage(){
        console.log("returning: "+errorMessage)
        return errorMessage;
}

and trying to display the error:

message= getMessage()
this.document.getElementById("myLabel").innerText=message;

On error, setMessage works but when another page tries to retrieve the message using getMessage as above it is initialized to unknown again.

How should I approach this problem in a JS way or just get my above code working?




Aucun commentaire:

Enregistrer un commentaire