Reading failure message from api

Hi,

I am using Uploader component with asp.net core 7.0 web api as backend. Upload and everything works fine but sometimes I need to return a custom error message.

No matter how I tried to do it, be it return BadRequest("My message"), or return Problem(...) or return StatusCode(...) this is what I get as part of onUploadFailure args:

response: {
    "readyState": 4,
    "statusCode": 400,
    "statusText": "Bad Request",
    "headers": "access-control-allow-origin: *\r\nconnection: keep-alive\r\ncontent-type: text/plain; charset=utf-8\r\ndate: Mon, 25 Sep 2023 19:52:16 GMT\r\nserver: Kestrel\r\ntransfer-encoding: chunked\r\nx-powered-by: Express\r\n",
    "withCredentials": false
}

Status text is always generic based on statusCode and not what I try to send from server. Is it possible to read custom error message?

Just to note, network tab in google chrome dev tools shows proper response with my custom message.


3 Replies

PK Priyanka Karthikeyan Syncfusion Team October 9, 2023 02:14 PM UTC

Hi Milan,

The uploader component enables you to make modifications to the file even after it has been uploaded to the server. This can be accomplished by utilizing the success and failure events of the uploader. For further details and guidance on achieving your specific requirement, please refer to the following forum.

https://www.syncfusion.com/forums/143272/set-custom-statustext-for-restuls-in-upload?reply=NS2UZX

If you find that this approach doesn't fully meet your requirements or if you have any additional questions or need further assistance, please don't hesitate to reach out to us. We are here to help and provide further guidance as needed.

Regards,

Priyanka K




MI Milan October 10, 2023 07:42 AM UTC

Thank you Priyanka,

This approach could indeed work but I didn't want to do extra work like adding extra heading and modifying response manually.

I eventually found out that I can get message that asp.net core api is sending by accessing args.e.currentTarget.responseText

Maybe this could help others too.



SS Shereen Shajahan Syncfusion Team October 11, 2023 06:59 AM UTC

Hi Milan,

Thank you for the update. Please get back to us for assistance in the future.

Regards,

Shereen


Loader.
Up arrow icon