web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to return 'Error 404' from a Custom Service API

(0) ShareShare
ReportReport
Posted on by 129

Hello Community,

i am developing an API on D365FO to expose data as Custom Service.
As i check no records were found, it should return a 404,
but a test ran from Postman receives a status 200 - ok

My returned JSON is ok, like below:

{
    "Company": "2",
    "InfologText": "Ciclo orçamentário 2022 não é válido.",
    "IntegEnvironment": 0,
    "Integration": 0,
    "ResultSet": []
}

Can anyone help how to change Response Status?

Thanks.

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: How to return 'Error 404' from a Custom Service API

    You can't define HTTP code of a custom service response by yourself. F&O give you only two options: success or failure (when you throw an exception).

    Maybe you could use Azure API Management to analyze the response, drop it and return 404 instead.

    By the way, consider creating another thread for your problem with Postman on DEV VM.

  • Hugo Alves Profile Picture
    129 on at
    RE: How to return 'Error 404' from a Custom Service API

    First of all, thanks Martin,
    but after these thoughts let me improve the question,
    and let´s make it a relevant future reference to this subject...

    Is it possible to either handle exceptions and also Change the Response Status to 404?
    (lets say i want to have control on replied Response JSON, or any other feasiable scenario)

    Or Throwing Error is recommended/possible approach to Reply Error on Custom Service?
    and in this case we have no control on replied JSON.

    Well, since i am not able to test Postman on DEV VM, it will take me some time to discover what error number the unhandled exception would return.

  • Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: How to return 'Error 404' from a Custom Service API

    This doesn't look like an exception to me. It seems that your service successfully returned data (such as BudgetCycleName) - therefore it handled the exception and didn't throw any - and it merely included infolog messages in InfoText property. You may want to debug you service to see where the exception got handled.

    It seems that somebody intentionally designed the service not to fail even if an exception occurs.

  • Hugo Alves Profile Picture
    129 on at
    RE: How to return 'Error 404' from a Custom Service API

    i've forced a Throw, but still i get Status 200 on Postman.

    API-Test-Postman.PNG

  • Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: How to return 'Error 404' from a Custom Service API

    Why don't you simply throw an exception, if you consider that a failure?

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: D365FO - How to return 'Error 404' from a Custom Service API

    moved to the d365 forum

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 882 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 723 Super User 2025 Season 2

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 518

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans