503 resonse code to json format


#1

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


#2

Yes, use the errorfile directive.


#3

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”
}


#4

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


#5

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.