The remote server returned an error: (500) Internal Server Error. Failed to parse

I have a module which has one service action, module type is also services. When i referenced that function in a UI module and try to call it, it gives below error:


The remote server returned an error: (500) Internal Server Error. Failed to parse the error response.
Environment InformationeSpaceVer: 0 (Id=1105, PubId=0, CompiledWith=11.0.108.0)
RequestUrl: https://
AppDomain: /LM/W3SVC/1/ROOT/LOSMain_UI-1-132210507104460022
Locale: en-US
DateFormat: yyyy-MM-dd
PID: 4144 ('w3wp', Started='12/17/2019 10:05:09 AM', Priv=1430Mb, Virt=2116205Mb)
TID: 53
Thread Name:
.NET: 4.0.30319.42000
Stack:
[1] The remote server returned an error: (500) Internal Server Error. Failed to parse the error response.
   at ssLOSMain_UI.RsseSpaceLOS_Services.LOS_ServicesServiceAPIClients.UploadDocumentToOmni(HeContext heContext, RLOmniDocDetailsList inParamInDocumentsDetail)
   at ssLOSMain_UI.RsseSpaceLOS_Services.UploadDocumentToOmni(HeContext heContext, RecordList inParamInDocumentsDetail)
   at ssLOSMain_UI.Flows.FlowCommon.WBlkFileUploader.CommandUploadFile(HeContext heContext)

[2] Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at OutSystems.RESTService.AbstractServiceAPIClient.ProcessErrorResponse(WebException e)


When I converted the same service action to server action, it works fine without any change.


Can anyone suggest what could be issue?


Other responses for old questions are discussing REST API, but it is not an API.


Hi Bilal,

You are doing a service call with an upload of a document to an omni channel. Service actions are actually API calls using REST with json, that's why the other questions are referring to REST.

To explain what is going on in your case:

During this upload, something goes wrong (unknown user, file too big, wrong type, missing mandatory field in the db or something else...) and you are not catching general errors. This causes your return value not to be of type json (internal service action return type), but an error-500 page (html).

That is why you get the error "Unexpected character encountered while parsing value: <". Your first returned character is "<" from "<html><body>error 500</body></html>" or something.

You need to debug the action "UploadDocumentToOmni" and see at which point it throws an error. Try capturing the error and returning it via a return variable. This should fix the error 500 and makes your service action return a normal value.

Service actions are not aware of any session. They don't know the user or any session related info, because they are running in a separate thread (as all API calls do).

Kind regards,

Remco Dekkinga


You should contact OutSystems Support team to check.


Remco Dekkinga wrote:

Hi Bilal,

You are doing a service call with an upload of a document to an omni channel. Service actions are actually API calls using REST with json, that's why the other questions are referring to REST.

To explain what is going on in your case:

During this upload, something goes wrong (unknown user, file too big, wrong type, missing mandatory field in the db or something else...) and you are not catching general errors. This causes your return value not to be of type json (internal service action return type), but an error-500 page (html).

That is why you get the error "Unexpected character encountered while parsing value: <". Your first returned character is "<" from "<html><body>error 500</body></html>" or something.

You need to debug the action "UploadDocumentToOmni" and see at which point it throws an error. Try capturing the error and returning it via a return variable. This should fix the error 500 and makes your service action return a normal value.

Service actions are not aware of any session. They don't know the user or any session related info, because they are running in a separate thread (as all API calls do).

Kind regards,

Remco Dekkinga


Remco,


I tried your approach and now i am sending back status instead of throwing any exception. But still it is having same behavior.


I have raised it to out-systems support as well.