Closed feathers-wing closed 5 years ago
As far as I know, there is no built-in method for changing content-type and converting the result to XML. You can simply implement it as the 'after' hook.
You can utilize something like that on the application for correctly configuration: https://www.npmjs.com/package/body-parser-xml
How to format the response is documented in the Express transport chapter. You can either use a global REST formatter or a service specific middleware.
thank you very much!!! 🌹🌹 i have a try!
Hello @daffl
I have noticed something. Let's take an example where I have the following hook:
// src/hooks/standardizeResponse.ts
import { HookContext } from '@feathersjs/feathers';
export const standardizeResponse = (context: HookContext) => {
const { result, error } = context;
if (error) {
context.result = {
status: 'error',
message: error.message || 'An error occurred',
data: null,
meta: {
errorCode: error.code || 'UNKNOWN',
timestamp: new Date().toISOString()
}
};
} else if (result) {
context.result = {
status: 'success',
message: 'Request was successful',
data: result,
meta: {
timestamp: new Date().toISOString()
}
};
}
return context;
};
which i intend to apply on the let say user service on:
after: {
all: [standardizeResponse]
},
error: {
all: [standardizeResponse]
}
/authetication is failing since it relies on the LocalStrategy.findEntity which does not expect the format given, I have tried to apply global on the global services on app.ts but still authetication api is failing. Kindly assist
You have to customize the strategy accordingly. Also note that your error handler will not return a proper error but instead turn it into a normal response. This might cause various issues when an actual error (and HTTP error code) is expected. This should probably still be context.error = {}
.
Hey @daffl thanks. I managed to implement the customize the strategy but the issue is with the authetication on getEntityQuery on authentication-local when the users response output is returned as a different format
You might have to re-implement the entire findEntity and getEntity to work with your format.
I need to return an XML format in content.result , and to set the content-type, but no method is found