200 OK - Unexpected Token Error - Spring Cloud Gateway Route Misconfiguration
search cancel

200 OK - Unexpected Token Error - Spring Cloud Gateway Route Misconfiguration

book

Article ID: 432961

calendar_today

Updated On:

Products

VMware Tanzu Platform - Cloud Foundry

Issue/Introduction

An application returned a `200 OK` response with an `Unexpected token '<'` error in the browser after a GCP key rotation and Spring Cloud Gateway service update. The application failed to parse the response because the API was returning an HTML page instead of the expected JSON.

Browser console error:

```
Status: 200
Unexpected token '<'
Content-Type: text/html; charset=utf-8
Server: nginx/1.29.4
```

Environment

Spring Cloud Gateway 2.4.1

Cause

The Spring Cloud Gateway service instance was updated. This update caused the gateway route configuration for the application to lose its backend URI mapping.

The gateway route is missing or pointing to an incorrect URI instead of the correct app route.

Resolution

  1. Confirm the misconfigured route in the Gateway Routes via SCG Dashboard
  2. Verify the URI field matches
  3. Verify that the correct CF routes are mapped
    • cf routes <app-name>
  4. Unbind the app from the gateway service
    • cf unbind <app-name> <gateway>
  5. Rebind the app with the correct route configuration
    • cf bind-service <app-name> <gateway> -c '{  "routes": [ { "path": "/example/**" } ] }'
  6. Restage the application
    • cf restage <app-name>