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

Announcements

No record found.

News and Announcements icon
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)
  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    moved to the d365 forum

  • Martin Dráb Profile Picture
    238,787 Most Valuable Professional on at

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

  • Hugo Alves Profile Picture
    129 on at

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

    API-Test-Postman.PNG

  • Martin Dráb Profile Picture
    238,787 Most Valuable Professional on at

    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

    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.

  • Verified answer
    Martin Dráb Profile Picture
    238,787 Most Valuable Professional on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 512 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 386

#3
Adis Profile Picture

Adis 259 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans