DidEncounterErrors

Hi Can anyone please help me with code example how to manipulate error object using didEncounterErrors in javascript code. I want to manipulate error object when some error occurs at restdatasoucre api class.
I want to make json object in such format that , I always return single object ,
like
response = {
data : {},
status : {
code: 200 or 404
message : success or error_message
}
}

but i want to return this object only , how to manipulate in such manner