HAProxy community

503 resonse code to json format


Is there any option to change haproxy error response code to json format. Please help.


Yes, use the errorfile directive.


Thanks for the update, I already done this.

    errorfile 503 /var/www/http/503.json
    errorfile 504 /var/www/http/504.json

But this case these json messges are printing on browser not as a valid json format.

My code:-
“code”: 100,
“longMessages”: [“No server is available to service the request. Please try again later.”],
“shortMessage”: “Gateway Error”,
“status”: “ERROR”


Did you read the documentation about errorfile? You need proper HTTP headers with CR-LF lineendings, not just your json payload.


Yaa, Looks great now. Modified the http header code with application/json insted of html and added rge json payload. Thank you @lukastribus Much appreciated.