I am getting different errors in both APIs even though the error returned from the Target API should match the error showed in the logs of the Source API.
Let's say there are 2 APIs. One of them (Source API) sends the payload to another API (Target API) where the payload is transformed and sent to the destination API. This should be the normal case.
In my case, the Source API sends the payload successfully to the Target API but an error occurs while transformation of the payload in the Target API. This would be a 422 error. The error in the logs of the Target API shows "HTTP PUT on resource 'URL' failed with status code 422." But while checking in the source API the error message in that API shows "HTTP PUT on resource 'URL' failed: internal server error (500)."
Is this something that everybody faces? I haven't messed with any error mapping. How do I rectify this so that both API's show the same error and I can handle that error in the Source API.
Your application "Source API" is not forwarding the HTTP status code from the request to the "Target API". By default since the request failed and the application doesn't handle the error it just returns an HTTP 500 internal error.
You could implement the error handling so it forwards that status to the client but you need to think if the error for the "Target API" is an appropriate response for "Source API". Maybe some other response would be more clear since the client may not be aware of what happens behind the API's implementation. That's something that only you can decide.