Tag Archives: Spartacus standard development

After SAP Spartacus successfully logs in, does the request base site need access token

I did test in two Spartacus instances,one is setup locally, the other one is http://cx-qa.eastus.cloudapp.azure.com:4200/

    create a new storefront using Schematics with version 3.1.

OCC endpoint: https://20.51.210.49:9002/
Login with url http://localhost:4200/electronics-spa/en/USD/
Wait for 1 minute till the access token is expired.
Refresh the browser.
Login page is displayed. This is working as designed.

    login with http://cx.eastus.cloudapp.azure.com:4200/

Wait for 1 minute till the access token is expired.
Refresh the browser.
No login page is displayed. Instead, blank screen is displayed.
The cause of blank page is, the OCC API to retrieve CMS structure of login page fails with 400 response:

Because the url itself is wrong:
https://20.51.210.49:9002/occ/v2/cms/pages?pageType=ContentPage&pageLabelOrId=%2Flogin&lang=en&curr=USD
The base site is missing in url.
The correct url should be:
https://20.51.210.49:9002/occ/v2/electronics-spa/cms/pages?pageType=ContentPage&pageLabelOrId=%2Flogin&lang=en&curr=USD
Due to this error, pageStructure.page is undefined, and the code below leads to JavaScript error in console. The login page fails to display. Then blank screen.

But why http://localhost:4200/electronics-spa/en/USD/ can work as expected?
In Spartacus 3.1, there is no Authorization field appended to OCC API for base site request:

But in our QA instance, the access token is appended in API request headers, so 401 error occurs.

Due to this error, base site cannot be retrieved, so subsequent request for login page structure is failed as well. Finally no login page displayed.
Here is some specific debugging information.
http://cx.eastus.cloudapp.azure.com:4200/electronics-spa/en/USD/

This method is called by cms-page.connector.ts.

Read the context of the login page.

This request to read the page structure of the login page has succeeded.

Request parameters successfully read.


The context is now only PreHeader and SiteLogin.





On a properly working local Storefront, the basesite request returns success:

401 error after SAP Spartacus access token expires

    login with url: http://cx-qa16181492.eastus.cloudapp.azure.com:4200/electronics-spa/en/USD

open Chrome dev tools to see access token is generated and stored in local storage.

    do nothing but just wait till the token expires.


Then press F5 to refresh the browser.

Then you see error message in Chrome dev tools console, and blank screen is displayed.

There are three 401 errors and two 400 errors observed in network tab:

SAP Spartacus encountered an error in the background of Commerce cloud when using the product configuration function


From the error log app_Kubernetes_io and docker_id, we know that the background system is a CCv2 system.

{
  "_index": "flb-2021.02.22",
  "_type": "flb_type",
  "_id": "b3243f97-d237-f049-3471-a181583767c1",
  "_version": 1,
  "_score": null,
  "_source": {
    "@fb_timestamp": "2021-02-22T14:13:41.254Z",
    "log": "{\"thread\":\"hybrisHTTP35\",\"level\":\"ERROR\",\"loggerName\":\"de.hybris.platform.sap.productconfig.runtime.cps.impl.RequestErrorHandlerImpl\",\"message\":\"While calling the cps service the following server error occured:{\\n  \\\"status\\\" : 412,\\n  \\\"typeId\\\" : \\\"40001\\\",\\n  \\\"type\\\" : \\\"precondition_failed\\\",\\n  \\\"message\\\" : \\\"Configuration is outdated\\\",\\n  \\\"moreInfo\\\" : null,\\n  \\\"details\\\" : [ ]\\n}\",\"endOfBatch\":false,\"loggerFqcn\":\"de.hybris.platform.util.logging.HybrisLogger\",\"instant\":{\"epochSecond\":1614003221,\"nanoOfSecond\":254006000},\"contextMap\":{\"RemoteAddr\":\"[194.153.147.4] \",\"Tenant\":\"\"},\"threadId\":206,\"threadPriority\":5,\"origin\":\"PLATFORM\"}\r\n",
    "stream": "stdout",
    "time": "2021-02-22T14:13:41.254242808Z",
    "logs": {
      "thread": "hybrisHTTP35",
      "level": "ERROR",
      "loggerName": "de.hybris.platform.sap.productconfig.runtime.cps.impl.RequestErrorHandlerImpl",
      "message": "While calling the cps service the following server error occured:{\n  \"status\" : 412,\n  \"typeId\" : \"40001\",\n  \"type\" : \"precondition_failed\",\n  \"message\" : \"Configuration is outdated\",\n  \"moreInfo\" : null,\n  \"details\" : [ ]\n}",
      "endOfBatch": false,
      "loggerFqcn": "de.hybris.platform.util.logging.HybrisLogger",
      "instant": {
        "epochSecond": 1614003221,
        "nanoOfSecond": 254006000
      },
      "contextMap": {
        "RemoteAddr": "[194.153.147.4] ",
        "Tenant": ""
      },
      "threadId": 206,
      "threadPriority": 5,
      "origin": "PLATFORM"
    },
    "kubernetes": {
      "pod_name": "api-55bc8d746f-fq9km",
      "namespace_name": "default",
      "pod_id": "099b8290-0cd9-49b3-9dd1-1e58be4b7a9f",
      "labels": {
        "app_kubernetes_io/component": "backend",
        "app_kubernetes_io/managed-by": "hybris-operator",
        "app_kubernetes_io/name": "hybris",
        "app_kubernetes_io/part-of": "hybris",
        "ccv2_cx_sap_com/platform-aspect": "api",
        "pod-template-hash": "55bc8d746f"
      },
      "annotations": {
        "ccv2_cx_sap_com/build-code": "20210218.2",
        "ccv2_cx_sap_com/deployment-id": "183528",
        "cni_projectcalico_org/podIP": "10.244.15.47/32",
        "fluentbit_io/parser": "mt-api",
        "platform-security-configmap-hash": "1996966820"
      },
      "host": "k8s-cwerwjw7gdkb-33420921-vmss00000j",
      "container_name": "platform",
      "docker_id": "676761e7499f414f0711daab4d15372e77e7addf36d93fc6f29522935c1eb2e1"
    }
  },
  "fields": {
    "@fb_timestamp": [
      "2021-02-22T14:13:41.254Z"
    ],
    "time": [
      "2021-02-22T14:13:41.254Z"
    ]
  },
  "highlight": {
    "logs.level": [
      "@kibana-highlighted-field@ERROR@/kibana-highlighted-field@"
    ]
  },
  "sort": [
    1614003221254
  ]
}

While calling the cps service the following server error occured: Configuration is outdated.