Closed laukaichung closed 7 years ago
Error comes from this line:
private async parseValue(value: any, paramMetadata: ParamMetadata) {
try {
const valueObject = typeof value === "string" ? JSON.parse(value) : value;
The parameter is parsed as JSON and it's invalid - you have escape chars in the JSON string.
This line looks bad for me: formData.append('json_data') = {id:5}
This isn't a correct call, check here. You should do sth like this:
formData.append('json_data', JSON.stringify({ id: 5 }));
@stonecold123 any updates on this issue?
okay Im closing this
My solution in the latest 0.1 version is adding this validation option as the second argument in BodyParam()
, like this:
@BodyParam("json_data",{validate:{skipMissingProperties:true}})
The BadRequest error returned from the controller isn't clear enough. I set a break point in the catch block in this part to understand the problem:
RoutingControllers.prototype.executeAction = function (actionMetadata, action, interceptorFns) {
var _this = this;
// compute all parameters
var paramsPromises = actionMetadata.params
.sort(function (param1, param2) { return param1.index - param2.index; })
.map(function (param) { return _this.parameterHandler.handle(action, param); });
// after all parameters are computed
return Promise.all(paramsPromises).then(function (params) {
// execute action and handle result
var allParams = actionMetadata.appendParams ? actionMetadata.appendParams(action).concat(params) : params;
var result = actionMetadata.methodOverride ? actionMetadata.methodOverride(actionMetadata, action, allParams) : actionMetadata.callMethod(allParams);
return _this.handleCallMethodResult(result, actionMetadata, action, interceptorFns);
}).catch(function (error) {
// otherwise simply handle error without action execution
return _this.driver.handleError(error, actionMetadata, action);
});
};
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
It seems that all of the
@EntityFromXXX
decorators no longer work with the latest 0.6.10 version when theparseJson
option is enable. There is a JsonParse error when transforming the string into a class.For example, client side:
server side:
It will throw:
The error seems to come from
if (!(value instanceof paramMetadata.format) && paramMetadata.format !== Object && paramMetadata.format && this.driver.useClassTransformer) {
in ParamHandler.js of the routing controllers: