Cannot create adCreative. Get an error:
Adcreative Create Failed: The Adcreative Create Failed for the following reason: Oops, something went wrong. Please try again later
and in the same error stack:
message: 'Invalid parameter'
code: 1487390
My code:
exports.create = (data, campaign) => {
return new adsSdk.AdCreative({
body: data.appearance.vacancyDescription,
image_url: data.appearance.backgroundImage,
name: `Creative for campaign ${campaign.id}`,
link_url: data.appearance.link,
title: data.appearance.linkDescription,
object_story_spec: {
instagram_actor_id: 'xxxxxx',
page_id: 'xxxxx',
link_data: {
link: data.appearance.link
}
}
}, `act_xxxxx`)
.create()
I'm using facebook-js-ads-sdk.
The problem was because of wrong page_id
Related
I'm trying to configure pusher on my nodejs app.
const Pusher = require("pusher");
const pusher = new Pusher({
appId: "id",
key: "key",
secret: "secret",
cluster: "ap2",
useTLS: true,
});
pusher.trigger('my-channel', 'my-event', {
message: "Hello, world."
}).then(console.log).catch(e=> console.log(e))
When I put above code in index and run, I get following error message.
{
name: 'PusherRequestError',
message: 'Unexpected status code 400',
url: 'a URL with all secret and stuff',
error: undefined,
status: 400,
body: 'expected string\n'
}
I double-checked the keys, secrets, etc and they are all correct. Any help is appreciated. Thanks!
I just want to implement Joi in Hapi API.
server.route([
{
method: 'POST',
path: '/login',
config: {
tags: ['login', 'auth'],
auth: false,
validate: {
payload: payloadValidator,
failAction: (req, h, source, error) => {
console.log("Error ::: ", source.details[0].message);
return h.response({ code: 0, message: source.details[0].message });
}
}
},
handler: async (request, h) => {
console.log(request.payload.email);
console.log(request.payload.password);
...
}
}
]);
Hear I call payloadValidator.
const payloadValidator = Joi.object({
email: Joi.string().required(),
password: Joi.string().required()
}).options({ allowUnknown: true });
Actually I'm new with hapi and I'm missing something in my code. Can anyone help me to fix this issue?
Required output
If I do not pass email then the app must throw an error of Email is required and it should be the same with the password field also.
Error:
Error ::: "email" is required
Debug: internal, implementation, error
Error: Lifecycle methods called before the handler can only return an error, a takeover response, or a continue signal
at Request._lifecycle (/var/www/html/hapi/node_modules/#hapi/hapi/lib/request.js:326:33)
at process._tickCallback (internal/process/next_tick.js:68:7)
As an error suggests Lifecycle methods called before the handler can only return an error, a takeover response, or a continue signal you have to return takeover response.
return h.response({ code: 0, message: source.details[0].message }).takeover();
For more information you can visit this link : reference link
How to display a specific error message from a Validation Error. I already display the error with this line of code return res.render("register", {error: err.message});
and show this error ValidationError: User validation failed: email: Email already exists
But it is showing my column field name 'email' and I don't wanna do that. Below is the whole error and I only want to display this message: 'Email already exists'
Ignore the location D: i removed my file directory
ValidationError: User validation failed: email: Email already exists
at ValidationError.inspect
errors:
{ email:
{ ValidatorError: Email already exists
at new ValidatorError (D:)
at validate (D:)
at D:
at process._tickCallback (internal/process/next_tick.js:68:7)
message: 'Email already exists',
name: 'ValidatorError',
properties: [Object],
kind: 'user defined',
path: 'email',
value: 'email#gmail.com',
reason: undefined,
[Symbol(mongoose:validatorError)]: true } },
_message: 'User validation failed',
name: 'ValidationError' }
To get a specific error message of Validation Error you can use mapped() function like below.
const errors = validationResult(req);
if (!errors.isEmpty()) {
console.log(errors.mapped().email.msg);
}
To access nested error message do this
err.errors.email.message
Simply create one temp variable and structure your message,
let err_msg = err.errors.email.message;
which will give: 'Email already exists'
You can leave user validation failed message, since same message may be repeated for all validations.
I have the following code, which does absolutely nothing, and for some reasons, I have an error with mongoose which is not even called, here's the code:
.post('/testRequest', express.json(), upload.none(), async (req, res) => {
try {
res.status(200);
res.send('test');
} catch (err) {
console.error(err.stack);
res.status(err.code || 400);
res.send(err.message || err);
}
})
And here's the error:
message: 'Cast to ObjectId failed for value "test" at path "_id" for model "Requests"',
name: 'CastError',
stringValue: '"test"',
kind: 'ObjectId',
value: 'test',
path: '_id',
reason: undefined,
I've tried many things but didn't seem to fix it
You probably have a .post(':id', ...) on top of your code. So a post request to /testRequest matches the '/:id' and '/testRequest' routes, but only the top one executes.
The ':id' route reads testRequest as an ID and throws the CastError.
You can swap the order of the methods, which was already discussed here.
I am using validator npm package to validate if email is correct.
All that i need is to send a custom message - Invalid Email
but I am getting this -
User validation failed: email: Invalid Email
const UserSchema = mongoose.Schema({
email:{
type: String,
unique: true,
required: true,
trim: true,
lowercase: true,
validate: [isEmail, 'Invalid Email']
},
});
All is good but when i am catching that error and logging it -
user.save().then(data => {
res.status(201).send(data);
}).catch(err => {
console.log(err.message); // this line here logs out the error message
return res.status(500).send({
message: err.message
});
})
I need this - Invalid Error instead of User validation failed: email: Invalid Email
Thanks in advance!
You have 2 solutions here:
1. Edit the validator package and remove the 'User validation failed' line totally.
2. Split the error message:
var errMessageArray = err.message.split(':');
var messageToReturn = errMessageArray[errMessageArray.length - 1]