500 (Internal Server Error)


#1

Hi,
I am calling the post api with ‘HttpHeaders’ in ionic 3, but getting ‘500 (Internal Server Error)’. Url & request body is correct. I’ve tried this on both the platform mobile & web. Receiving this error: “Response for preflight has invalid HTTP status code 500.” in console.
Please help me, if I am doing something wrong.

//Request
var filterProperty={
offset:0,
recordlimit:10,
orderby: “formname”
};

var filters:Array<{ fieldname: string, fieldvalue: any, operators: string }>;

filters=[{
  fieldname: "formid",
  fieldvalue:["1"],
  operators: "In"
}];

var filterRequest ={
    app:true,
    auth: false,
    filter: filters,
    filterproperty:filterProperty
};

//Api call
var httpHeaders=new HttpHeaders();
httpHeaders.set(‘Accept’,‘application/json’);
httpHeaders.set(‘Source-Api’, ‘wemaplus’);

var url=‘http://wema-env-design.eu-west-2.elasticbeanstalk.com/data/api/formbuilder’;

var response= this.httpClient.post(url,filterRequest,
  {
    headers:httpHeaders
  });
return response;

#2

Any time I see the word “preflight”, I assume the problem is CORS-related.


#3

It of course is, the server is returning an error 500 to requests of the OPTIONS type. Nothing you can do about that in the JS/TS code - you have to fix your server.


#4

Yeah , I see. It’s a CORS issue.
I’ve added proxy in ‘ionic.config.json’ file, but it’s not working.

{
“name”: “myApp”,
“app_id”: “”,
“type”: “ionic-angular”,
“integrations”: {
“cordova”: {}
},
“proxies”: [
{
“path”: “/api”,
“proxyUrl”: “http://wema-env-design.eu-west-2.elasticbeanstalk.com/data
}
]
}


#5

Now, I am getting this response:

{“status”:false,“error”:“Unsupported content-type”}

Status Code: 203 Non-Authoritative Information