Warning message in JSON-API " Illegal header: Illegal 'origin' header: Illegal origin: Invalid input '/"

I am experimenting with the JSON-API and notice this specific warning message in the console output

13:29:50.272 [http-json-ledger-api-akka.actor.default-dispatcher-10] WARN akka.actor.ActorSystemImpl - Illegal header: Illegal ‘origin’ header: Illegal origin: Invalid input ‘/’, expected DIGIT or ‘EOI’ (line 1, column 22): http://localhost:7575/

I am running SDK 1.1.1

I am also running to the following script to start the JSON-API

daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --max-inbound-message-size 4194304 --package-reload-interval 5s --application-id HTTP-JSON-API-Gateway --static-content “prefix=static,directory=./static-content” --access-token-file ./token/token --query-store-jdbc-config "driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/test?&ssl=false,user=Bart,password=password,createSchema=false

"
In my code I have a .catch(error) and it keeps on getting triggered although the ledger.execise function return 200 code

const exerciseInviteCitizen = function() {

let roletype = "Citizen"
let citizen = partyname.namecitizen
ledger.exercise(Main.Network.InviteCitizen, curContractId, { operator, citizen , roletype } )
.then(() => {
  setValidate({
    status: 0,
    message: 'Citizen is successfully stored!'
  });
})
.catch((error) => {
  setValidate({
    status: 1,
    message: 'Error: Invalid Citizen'
  });
});

Could this be triggered by the above “illegal header” ?
How do I fix the illegal header issue ?

Hi @bartcant, the illegal header error most likely comes from an incorrect proxy configuration. This was fixed in the ui-template in remove trailing slash for proxy · digital-asset/daml-ui-template@61f1320 · GitHub. You can probably adapt that for your project.

As for the non-200 response, afaik the illegal header warning is purely a warning and does not change the response so it should not cause that issue. Have you tried looking at the network inspector of your browser to see what response you get or tried to print out the error in your handler?

1 Like

The trailing slash for Proxy fixed the warning

It did not solve my other issue.

I am still looping into the .catch((error) =>
Although the JSON response is

{“result”:{“exerciseResult”:“0089ad9ff683c136550e092e26dda28ebeaaaba4ba23ef5f2b7d3122b5c9164f94”,“events”:[{“created”:{“observers”:[“Bob”],“agreementText”:“”,“payload”:{“operator”:“Operator”,“citizen”:“Bob”,“roletype”:“Citizen”},“signatories”:[“Operator”],“key”:{“_1”:“Operator”,“_2”:“Bob”},“contractId”:“0089ad9ff683c136550e092e26dda28ebeaaaba4ba23ef5f2b7d3122b5c9164f94”,“templateId”:“14a8c7e373599e1fa28c8eb42e2841c42a235f0c8ed70d8a67b0db50768ef99e:Main:CitizenInvitation”}}]},“status”:200}

Does this maybe have to do with the timing of the response in React ?

Ok which may bring some clarity…

I have added console.log

.catch((error) => {
console.log("error: " + error);
setValidate({
status: 1,
message: ‘Error: Invalid Citizen’
});

Here is the console.log output :

Error: Trying to look up template 14a8c7e373599e1fa28c8eb42e2841c42a235f0c8ed70d8a67b0db50768ef99e:Main:CitizenInvitation.

This template is in the database

The Trying to look up template error comes from the JS codegen. My guess is that you ended up in an inconsistent state for some reason. I recommend following the instructions in Daml-ui-template React function and Action with 2 arguments to try and fix it.

Side note: The DB schema used by Sandox on Postgres is considered an implementation detail and not something you should rely on. To answer the query you used here you can use the package management service on the ledger API instead.

I think I fixed the issue by executing the following 2 steps. Either one could have solved it

  1. I upgraded to lastest SDK 1.2.0 and rebuild daml , codegen etc
  2. I updated the JWT token for the JSON-API and added in Payload

“readAs” : [“Operator”]

 "https://daml.com/ledger-api": {
     "ledgerId": "Covid19",
    "applicationId": "foobar",
    "actAs": ["Operator"],
     "readAs" : ["Operator"]
  }
}

actAs implies readAs so I expect it was step 1. Either way, glad you got it working!

@alexander and I multiple times deleted directories and rebuild , but still were running into the Template issue.
Even the Nuclear option did not solve our problems. I guess by upgrading the SDK it really cleared the lingering templates.