I am new to discord.js and I am wondering how to fix this error. Could you please fix my code and then also tell me how to avoid this issue in the future? Thanks!
Code:
client.on('message', message => {
if (message.content === '-ping') {
const embed = {
"title": "**Ping Results**",
"fields": [
{
"name": "Bot",
"value": "" +(botMsg.createdAt - message.createdAt) + "ms"
},
{
"name": "API ",
"value": Math.round(client.ping) + "ms"
},
{
"name": "Uptime",
"value": msToTime(client.uptime) + "ms"
}
]
};
message.channel.send({ embed });
}
});
Console Error:
ReferenceError: botMsg is not defined
at Client.<anonymous> (C:\Users\parke\Documents\Discord Bot\index.js:15:31)
at Client.emit (events.js:314:20)
at MessageCreateAction.handle (C:\Users\parke\Documents\Discord Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\parke\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\parke\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\parke\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\parke\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\parke\Documents\Discord Bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:314:20)
at Receiver.receiverOnMessage (C:\Users\parke\Documents\Discord Bot\node_modules\ws\lib\websocket.js:797:20)
This error means that the variable botMsg is not defined.
As I can see you want to make a ping command and botMsg is a message sent that you want to collect.
This code should work.
client.on('message', message => {
if (message.content === '-ping') {
message.channel.send("Checking the ping...").then(botMsg => {
const embed = {
"title": "**Ping Results**",
"fields": [
{
"name": "Bot",
"value": "" +(botMsg.createdAt - message.createdAt) + "ms"
},
{
"name": "API ",
"value": Math.round(client.ping) + "ms"
},
{
"name": "Uptime",
"value": msToTime(client.uptime) + "ms"
}
]
};
botMsg.edit({ embed });
})
}
});
Related
I set up a Hyperledger Fabric 2.2 network successfully but unable to query/invoke assets through nodeJs SDK. The node version I am using is 16. I think the issue is with grpc most probably. I was able to create assets when I was using node version 12 but not with version 16
Error snippet
Loaded the network configuration located at /home/harsh/Videos/standardc-backend-master-v3-dlt/fabric-network-setup/fabric-swarm/common-connection-profile.json
Connect to Fabric gateway.
2023-02-13T15:28:45.076Z - info: [NetworkConfig]: buildOrderer - Unable to connect to the committer ord1_standardc_io due to TypeError: Channel credentials must be a ChannelCredentials object
at new ChannelImplementation (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/channel.js:102:19)
at new Client (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/client.js:65:36)
at new ServiceClientImpl (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/make-client.js:58:5)
at Committer.connect (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/node_modules/fabric-common/lib/ServiceEndpoint.js:120:18)
at buildOrderer (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:103:23)
at async Object.loadFromConfig (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:50:13)
at async Gateway.connect (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/gateway.js:299:13)
at async evaluate (/home/harsh/Videos/standardc-backend-master-v3-dlt/modules/dlt/commonHyperledgerHelpers/query.js:50:5)
at async queryAssetById (/home/harsh/Videos/standardc-backend-master-v3-dlt/modules/dlt/asset/asset.js:149:20)
2023-02-13T15:28:45.080Z - info: [NetworkConfig]: buildOrderer - Unable to connect to the committer ord2_standardc_io due to TypeError: Channel credentials must be a ChannelCredentials object
at new ChannelImplementation (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/channel.js:102:19)
at new Client (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/client.js:65:36)
at new ServiceClientImpl (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/make-client.js:58:5)
at Committer.connect (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/node_modules/fabric-common/lib/ServiceEndpoint.js:120:18)
at buildOrderer (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:103:23)
at async Object.loadFromConfig (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:50:13)
at async Gateway.connect (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/gateway.js:299:13)
at async evaluate (/home/harsh/Videos/standardc-backend-master-v3-dlt/modules/dlt/commonHyperledgerHelpers/query.js:50:5)
at async queryAssetById (/home/harsh/Videos/standardc-backend-master-v3-dlt/modules/dlt/asset/asset.js:149:20)
2023-02-13T15:28:45.083Z - info: [NetworkConfig]: buildOrderer - Unable to connect to the committer ord3_standardc_io due to TypeError: Channel credentials must be a ChannelCredentials object
at new ChannelImplementation (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/channel.js:102:19)
at new Client (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/client.js:65:36)
at new ServiceClientImpl (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-common/node_modules/#grpc/grpc-js/build/src/make-client.js:58:5)
at Committer.connect (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/node_modules/fabric-common/lib/ServiceEndpoint.js:120:18)
at buildOrderer (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:103:23)
at async Object.loadFromConfig (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:50:13)
at async Gateway.connect (/home/harsh/Videos/standardc-backend-master-v3-dlt/node_modules/fabric-network/lib/gateway.js:299:13)
at async evaluate (/home/harsh/Videos/standardc-backend-master-v3-dlt/modules/dlt/commonHyperledgerHelpers/query.js:50:5)
at async queryAssetById (/home/harsh/Videos/standardc-backend-master-v3-dlt/modules/dlt/asset/asset.js:149:20)
Use network channel: standardcdltchannel.
2023-02-13T15:28:45.161Z - error: [ServiceEndpoint]: ServiceEndpoint grpcs://localhost:7050 reset connection failed :: TypeError: Channel credentials must be a ChannelCredentials object
2023-02-13T15:28:45.163Z - error: [ServiceEndpoint]: ServiceEndpoint grpcs://localhost:7050 reset connection failed :: TypeError: Channel credentials must be a ChannelCredentials object
2023-02-13T15:28:45.165Z - error: [ServiceEndpoint]: ServiceEndpoint grpcs://localhost:7050 reset connection failed :: TypeError: Channel credentials must be a ChannelCredentials object
Common-connection-profile
{
"name": "abcd",
"version": "1.0.0",
"channels": {
"standardcdltchannel": {
"orderers": [
"ord1_standardc_io",
"ord2_standardc_io",
"ord3_standardc_io"
],
"peers": [
"a1_admin_standardc_io",
"a2_admin_standardc_io",
"a1_fin_standardc_io",
"a2_fin_standardc_io",
"a1_user_standardc_io",
"a2_user_standardc_io"
]
}
},
"orderers": {
"ord1_standardc_io": {
"url": "grpcs://localhost:7050",
"grpcOptions": {
"ssl-target-name-override": "ord1_standardc_io"
},
"tlsCACerts": {
"path": "fabric-network-setup/fabric-swarm/crypto-config/ordererOrganizations/standardc_io/orderers/ord1_standardc_io/tls/ca.crt"
}
},
"ord2_standardc_io": {
"url": "grpcs://localhost:8050",
"grpcOptions": {
"ssl-target-name-override": "ord2_standardc_io"
},
"tlsCACerts": {
"path": "fabric-network-setup/fabric-swarm/crypto-config/ordererOrganizations/standardc_io/orderers/ord2_standardc_io/tls/ca.crt"
}
},
"ord3_standardc_io": {
"url": "grpcs://localhost:9050",
"grpcOptions": {
"ssl-target-name-override": "ord3_standardc_io"
},
"tlsCACerts": {
"path": "fabric-network-setup/fabric-swarm/crypto-config/ordererOrganizations/standardc_io/orderers/ord3_standardc_io/tls/ca.crt"
}
}
},
"organizations": {
"StandardCAdmin": {
"mspid": "StandardCAdminMSP",
"peers": [
"a1_admin_standardc_io",
"a2_admin_standardc_io"
],
"certificateAuthorities": [
"ca_StandardCAdmin"
]
},
"StandardCFin": {
"mspid": "StandardCFinMSP",
"peers": [
"a1_fin_standardc_io",
"a2_fin_standardc_io"
],
"certificateAuthorities": [
"ca_StandardCFin"
]
},
"StandardCUser": {
"mspid": "StandardCUserMSP",
"peers": [
"a1_user_standardc_io",
"a2_user_standardc_io"
],
"certificateAuthorities": [
"ca_StandardCUser"
]
}
},
"peers": {
"a1_admin_standardc_io": {
"url": "grpcs://localhost:7051",
"grpcOptions": {
"ssl-target-name-override": "a1_admin_standardc_io",
"hostnameOverride": "a1_admin_standardc_io"
},
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICXzCCAgagAwIBAgIRAPGMIxMpZ7KcQuC1J115hKcwCgYIKoZIzj0EAwIwejEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGzAZBgNVBAoMEmFkbWluX3N0YW5kYXJkY19pbzEhMB8GA1UEAwwY\ndGxzY2EuYWRtaW5fc3RhbmRhcmRjX2lvMB4XDTIzMDIxMzEwNDEwMFoXDTMzMDIx\nMDEwNDEwMFowejELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAU\nBgNVBAcTDVNhbiBGcmFuY2lzY28xGzAZBgNVBAoMEmFkbWluX3N0YW5kYXJkY19p\nbzEhMB8GA1UEAwwYdGxzY2EuYWRtaW5fc3RhbmRhcmRjX2lvMFkwEwYHKoZIzj0C\nAQYIKoZIzj0DAQcDQgAEP7hrn3FOgSIoV2OFpF5N448bXLg8NdwWSXJ76xra1Dsj\nJfS6+A6OKp+4X0VZ7vfUqvVNSj0vU611osqopRYWt6NtMGswDgYDVR0PAQH/BAQD\nAgGmMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTAD\nAQH/MCkGA1UdDgQiBCCxhxWEEntqKYczzMh3sncOGFwiP9XB8U/hmUTRFnboWzAK\nBggqhkjOPQQDAgNHADBEAiAf3ZbcFLushIlfZ4dD67SVUMay6EdUE7mPvsUXXLqF\nQwIgeRFexyjDtl3bAnCrf/KNe9uPq/epZWXMvS+JnGgBO8s=\n-----END CERTIFICATE-----\n"
}
},
"a2_admin_standardc_io": {
"url": "grpcs://localhost:10105",
"grpcOptions": {
"ssl-target-name-override": "a2_admin_standardc_io",
"hostnameOverride": "a2_admin_standardc_io"
},
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICXzCCAgagAwIBAgIRAPGMIxMpZ7KcQuC1J115hKcwCgYIKoZIzj0EAwIwejEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGzAZBgNVBAoMEmFkbWluX3N0YW5kYXJkY19pbzEhMB8GA1UEAwwY\ndGxzY2EuYWRtaW5fc3RhbmRhcmRjX2lvMB4XDTIzMDIxMzEwNDEwMFoXDTMzMDIx\nMDEwNDEwMFowejELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAU\nBgNVBAcTDVNhbiBGcmFuY2lzY28xGzAZBgNVBAoMEmFkbWluX3N0YW5kYXJkY19p\nbzEhMB8GA1UEAwwYdGxzY2EuYWRtaW5fc3RhbmRhcmRjX2lvMFkwEwYHKoZIzj0C\nAQYIKoZIzj0DAQcDQgAEP7hrn3FOgSIoV2OFpF5N448bXLg8NdwWSXJ76xra1Dsj\nJfS6+A6OKp+4X0VZ7vfUqvVNSj0vU611osqopRYWt6NtMGswDgYDVR0PAQH/BAQD\nAgGmMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTAD\nAQH/MCkGA1UdDgQiBCCxhxWEEntqKYczzMh3sncOGFwiP9XB8U/hmUTRFnboWzAK\nBggqhkjOPQQDAgNHADBEAiAf3ZbcFLushIlfZ4dD67SVUMay6EdUE7mPvsUXXLqF\nQwIgeRFexyjDtl3bAnCrf/KNe9uPq/epZWXMvS+JnGgBO8s=\n-----END CERTIFICATE-----\n"
}
},
"a1_fin_standardc_io": {
"url": "grpcs://localhost:8051",
"grpcOptions": {
"ssl-target-name-override": "a1_fin_standardc_io",
"hostnameOverride": "a1_fin_standardc_io"
},
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICWDCCAf6gAwIBAgIRAPLNPsjll3MJ1JtK4H2n7SIwCgYIKoZIzj0EAwIwdjEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoMEGZpbl9zdGFuZGFyZGNfaW8xHzAdBgNVBAMMFnRs\nc2NhLmZpbl9zdGFuZGFyZGNfaW8wHhcNMjMwMjEzMTA0MTAwWhcNMzMwMjEwMTA0\nMTAwWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE\nBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UECgwQZmluX3N0YW5kYXJkY19pbzEfMB0G\nA1UEAwwWdGxzY2EuZmluX3N0YW5kYXJkY19pbzBZMBMGByqGSM49AgEGCCqGSM49\nAwEHA0IABDpbUyoFRVo7xoIuTCwmCosJujfQbMDNuO9d9ZrouyR6Z+hHsHygBnSU\nL5TjSQ5rBHicwVWDhpD+p3UTiqNH1cyjbTBrMA4GA1UdDwEB/wQEAwIBpjAdBgNV\nHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zApBgNV\nHQ4EIgQgBW/ha6XUwwxfLHUbngYe1fFSi7wE2YHvVnLrCmjaIQQwCgYIKoZIzj0E\nAwIDSAAwRQIhAPhfFS5BwyQ9kGj7+YR8U+yXyNK42J89Ym77oTtTjKlmAiB5Q3yk\nagyJDOrYyxmAXu+7YgrYUD0Hu6BOVWk6ply7Pg==\n-----END CERTIFICATE-----\n"
}
},
"a2_fin_standardc_io": {
"url": "grpcs://localhost:10205",
"grpcOptions": {
"ssl-target-name-override": "a2_fin_standardc_io",
"hostnameOverride": "a2_fin_standardc_io"
},
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICWDCCAf6gAwIBAgIRAPLNPsjll3MJ1JtK4H2n7SIwCgYIKoZIzj0EAwIwdjEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoMEGZpbl9zdGFuZGFyZGNfaW8xHzAdBgNVBAMMFnRs\nc2NhLmZpbl9zdGFuZGFyZGNfaW8wHhcNMjMwMjEzMTA0MTAwWhcNMzMwMjEwMTA0\nMTAwWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE\nBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UECgwQZmluX3N0YW5kYXJkY19pbzEfMB0G\nA1UEAwwWdGxzY2EuZmluX3N0YW5kYXJkY19pbzBZMBMGByqGSM49AgEGCCqGSM49\nAwEHA0IABDpbUyoFRVo7xoIuTCwmCosJujfQbMDNuO9d9ZrouyR6Z+hHsHygBnSU\nL5TjSQ5rBHicwVWDhpD+p3UTiqNH1cyjbTBrMA4GA1UdDwEB/wQEAwIBpjAdBgNV\nHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zApBgNV\nHQ4EIgQgBW/ha6XUwwxfLHUbngYe1fFSi7wE2YHvVnLrCmjaIQQwCgYIKoZIzj0E\nAwIDSAAwRQIhAPhfFS5BwyQ9kGj7+YR8U+yXyNK42J89Ym77oTtTjKlmAiB5Q3yk\nagyJDOrYyxmAXu+7YgrYUD0Hu6BOVWk6ply7Pg==\n-----END CERTIFICATE-----\n"
}
},
"a1_user_standardc_io": {
"url": "grpcs://localhost:9051",
"grpcOptions": {
"ssl-target-name-override": "a1_user_standardc_io",
"hostnameOverride": "a1_user_standardc_io"
},
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICWzCCAgGgAwIBAgIQfzttriKt8PjPCq6ahVRsgTAKBggqhkjOPQQDAjB4MQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEaMBgGA1UECgwRdXNlcl9zdGFuZGFyZGNfaW8xIDAeBgNVBAMMF3Rs\nc2NhLnVzZXJfc3RhbmRhcmRjX2lvMB4XDTIzMDIxMzEwNDEwMFoXDTMzMDIxMDEw\nNDEwMFoweDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNV\nBAcTDVNhbiBGcmFuY2lzY28xGjAYBgNVBAoMEXVzZXJfc3RhbmRhcmRjX2lvMSAw\nHgYDVQQDDBd0bHNjYS51c2VyX3N0YW5kYXJkY19pbzBZMBMGByqGSM49AgEGCCqG\nSM49AwEHA0IABEEH6Km7J/yMIPVmV5xHGO4z/70817YsUB3vhEcPzW24Utb9Fa4z\nV5PFL1F3THPCC03/j6FKkH2Sb8U5kR6H4A2jbTBrMA4GA1UdDwEB/wQEAwIBpjAd\nBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zAp\nBgNVHQ4EIgQgeiTgppGQVAIkzh/rUj/mkAvrzo02U42GQ+yqISd+0akwCgYIKoZI\nzj0EAwIDSAAwRQIhAK2Jif9AmcyXMjw0QtNsqvynrdHEhsrkRH3faCfxa0ECAiBS\njXiY+4T66F//0F4xk1FUhJaeZQCm5hCYt/h1AlNi6g==\n-----END CERTIFICATE-----\n"
}
},
"a2_user_standardc_io": {
"url": "grpcs://localhost:10305",
"grpcOptions": {
"ssl-target-name-override": "a2_user_standardc_io",
"hostnameOverride": "a2_user_standardc_io"
},
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICWzCCAgGgAwIBAgIQfzttriKt8PjPCq6ahVRsgTAKBggqhkjOPQQDAjB4MQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEaMBgGA1UECgwRdXNlcl9zdGFuZGFyZGNfaW8xIDAeBgNVBAMMF3Rs\nc2NhLnVzZXJfc3RhbmRhcmRjX2lvMB4XDTIzMDIxMzEwNDEwMFoXDTMzMDIxMDEw\nNDEwMFoweDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNV\nBAcTDVNhbiBGcmFuY2lzY28xGjAYBgNVBAoMEXVzZXJfc3RhbmRhcmRjX2lvMSAw\nHgYDVQQDDBd0bHNjYS51c2VyX3N0YW5kYXJkY19pbzBZMBMGByqGSM49AgEGCCqG\nSM49AwEHA0IABEEH6Km7J/yMIPVmV5xHGO4z/70817YsUB3vhEcPzW24Utb9Fa4z\nV5PFL1F3THPCC03/j6FKkH2Sb8U5kR6H4A2jbTBrMA4GA1UdDwEB/wQEAwIBpjAd\nBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zAp\nBgNVHQ4EIgQgeiTgppGQVAIkzh/rUj/mkAvrzo02U42GQ+yqISd+0akwCgYIKoZI\nzj0EAwIDSAAwRQIhAK2Jif9AmcyXMjw0QtNsqvynrdHEhsrkRH3faCfxa0ECAiBS\njXiY+4T66F//0F4xk1FUhJaeZQCm5hCYt/h1AlNi6g==\n-----END CERTIFICATE-----\n"
}
}
},
"certificateAuthorities": {
"ca_StandardCAdmin": {
"url": "https://localhost:7054",
"caName": "ca_StandardCAdmin",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICWTCCAf+gAwIBAgIQGqmY2TnbrYHpfSLWJG9slzAKBggqhkjOPQQDAjB3MQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEbMBkGA1UECgwSYWRtaW5fc3RhbmRhcmRjX2lvMR4wHAYDVQQDDBVj\nYS5hZG1pbl9zdGFuZGFyZGNfaW8wHhcNMjMwMjEzMTA0MTAwWhcNMzMwMjEwMTA0\nMTAwWjB3MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE\nBxMNU2FuIEZyYW5jaXNjbzEbMBkGA1UECgwSYWRtaW5fc3RhbmRhcmRjX2lvMR4w\nHAYDVQQDDBVjYS5hZG1pbl9zdGFuZGFyZGNfaW8wWTATBgcqhkjOPQIBBggqhkjO\nPQMBBwNCAAQjAX9P5VDzrYNCyAX3VVyx+b2Zj6ksqr0kjwrK7p7tw44Re9gDnrZx\ns1T4TQtays+3vdJVrcR60XfljJah5KHLo20wazAOBgNVHQ8BAf8EBAMCAaYwHQYD\nVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMA8GA1UdEwEB/wQFMAMBAf8wKQYD\nVR0OBCIEINP68n78uQQUXLyEj8Z3t7i+P6DAhLTrqxZg4Z6STy/HMAoGCCqGSM49\nBAMCA0gAMEUCIQCwErwt0jkJCvEXMNKK4wfHdr7bc+VJBwTx/+55wPDq7gIgS++Q\nHoo9XcFa0tTxaHIXlw/RSUHyhjtlQcbmQkGYTxc=\n-----END CERTIFICATE-----\n"
},
"httpOptions": {
"verify": false
}
},
"ca_StandardCFin": {
"url": "https://localhost:8054",
"caName": "ca_StandardCFin",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICUTCCAfegAwIBAgIQF73X1H/A97e8dD9ONdx+uzAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UECgwQZmluX3N0YW5kYXJkY19pbzEcMBoGA1UEAwwTY2Eu\nZmluX3N0YW5kYXJkY19pbzAeFw0yMzAyMTMxMDQxMDBaFw0zMzAyMTAxMDQxMDBa\nMHMxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMRkwFwYDVQQKDBBmaW5fc3RhbmRhcmRjX2lvMRwwGgYDVQQD\nDBNjYS5maW5fc3RhbmRhcmRjX2lvMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\n7okOZKS2UcKbXyPTcuUKm4IwyixTop0acLApHul7jdHlCagaHHp8ZRDkujrSMwFW\nSE2XyAliby+qKBZzTo4Tp6NtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1UdJQQWMBQG\nCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdDgQiBCDQ\nLKzwFEERdwOuOiXqe6NWzDHsX7n0uhQYhMS/SvWToTAKBggqhkjOPQQDAgNIADBF\nAiEA6bFSIeCZlSnIQJ8SEhMgaLyk0QQmxeE9KzbeJEAyhAUCIBNaZUC0YGXB2mm4\nYHbxf0BYRgLI+/tNMD20NwqVr6MQ\n-----END CERTIFICATE-----\n"
},
"httpOptions": {
"verify": false
}
},
"ca_StandardCUser": {
"url": "https://localhost:9054",
"caName": "ca_StandardCUser",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICVDCCAfugAwIBAgIQcJ3I4sJZB/aozh8fz5Pu4jAKBggqhkjOPQQDAjB1MQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEaMBgGA1UECgwRdXNlcl9zdGFuZGFyZGNfaW8xHTAbBgNVBAMMFGNh\nLnVzZXJfc3RhbmRhcmRjX2lvMB4XDTIzMDIxMzEwNDEwMFoXDTMzMDIxMDEwNDEw\nMFowdTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcT\nDVNhbiBGcmFuY2lzY28xGjAYBgNVBAoMEXVzZXJfc3RhbmRhcmRjX2lvMR0wGwYD\nVQQDDBRjYS51c2VyX3N0YW5kYXJkY19pbzBZMBMGByqGSM49AgEGCCqGSM49AwEH\nA0IABFZqnLYHyueJRTde2is1GE0NTch7/7wIbic3TWsGp3nIbr/qQOeO4C/sKQcr\na10IeAxOqygPCvX1PhVAyuXIADajbTBrMA4GA1UdDwEB/wQEAwIBpjAdBgNVHSUE\nFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4E\nIgQgfw82nvAsVC+uPtAETYmU5QFTzfW6e4FYdP713usdKQQwCgYIKoZIzj0EAwID\nRwAwRAIgcbiH6oGe17/7gYJ/8JL7NZSjNzmkdZPOuPX55TD7d+MCICdc+U++8S1j\nCoxSHhmGiDjQ4nejCelav69jwV3KlVqy\n-----END CERTIFICATE-----\n"
},
"httpOptions": {
"verify": false
}
}
}
}
package.json with essentials details
{
"name": "abcd-backend",
"version": "3.0.0-476-230212",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
},
"dependencies": {
"fabric-ca-client": "^2.2.15",
"fabric-client": "^1.4.18",
"fabric-common": "^2.2.16",
"fabric-network": "^2.2.15",
"grpc": "^1.24.11"
}
}
The error "TypeError:Channel credentials must be a ChannelCredentials object" happens most commonly because the gRPC library that was used to create the ChannelCredentials object does not match the gRPC library that it was passed to to create a Channel. In this case, the error is coming from the library #grpc/grpc-js, but you have a dependency on grpc. If you used grpc to create the credentials object, that would cause this error. You should depend on #grpc/grpc-js instead.
This is a single product data .
const [single, setSingle]= useState([])
setSingle(res.data) (axios set state)
{
"id": 135,
"device_detail": [
{
"type": "high-speed",
"brief": "dsf",
"model": "ds",
"serial": "ds"
},
{
"type": "low-speed",
"brief": "dfg",
"model": "hgj",
"serial": "dsf"
}
],
"device_name": "Handpieces",
"practice_name": "dsf",
"unit": "dsf",
"street": "dsf",,
"status": 1,
"created_at": "2021-03-02 14:00:58.295738+00:00"
}
When i use
{single.device_detail.map((subd,index)=>(
(index ? ', ' : '') + subd.type
))}
its saying TypeError: Cannot read property ‘map’ of undefined :
but when i make another state for device_detail and then its working like this:
const [dd, setdd]= useState([])
setdd(res.data.device_detail) (axios set state)
But, i this is not a proper solution.
Any idea?
Currently trying to upload an image and connect it to an existing entry.
The schema of the existing entry is
{
"name": "page rows",
"description": "",
"connection": "default",
"kind": "collectionType",
"collectionName": "page_rows",
"attributes": {
"row": {
"type": "json"
},
"images": {
"type": "media",
"multiple": true,
"required": false,
"allowedTypes": [
"images"
]
}
}
},
and I upload an image using
export const formatEntryUpload = (file, entryModel, entryID, entryField, entryPlugin = null) => {
const entryUpload = new FormData();
entryUpload.append('files', file);
entryUpload.append('ref', entryModel);
entryUpload.append('refId', entryID);
entryUpload.append('field', entryField);
if(entryPlugin) {
entryUpload.append('source', entryPlugin);
}
return entryUpload;
};
where I fill call the function by
formatEntryUpload ( file, "page_rows", id, "images", "users-permissions");
however when I do I get the following error.
[2021-02-07T21:01:35.334Z] error TypeError: Cannot read property 'associations' of undefined
at /srv/app/node_modules/strapi-connector-mongoose/lib/relations.js:250:43
at Array.forEach (<anonymous>)
at /srv/app/node_modules/strapi-connector-mongoose/lib/relations.js:235:20
at Array.reduce (<anonymous>)
at Function.update [as updateRelations] (/srv/app/node_modules/strapi-connector-mongoose/lib/relations.js:97:68)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Object.add (/srv/app/node_modules/strapi-plugin-upload/services/Upload.js:253:17)
at async Promise.all (index 0)
at async Object.upload (/srv/app/node_modules/strapi-plugin-upload/services/Upload.js:105:12)
at async Object.upload (/srv/app/node_modules/strapi-plugin-upload/controllers/Upload.js:82:18)
at async /srv/app/node_modules/strapi/lib/middlewares/router/utils/routerChecker.js:70:22
at async module.exports (/srv/app/node_modules/strapi-plugin-users-permissions/config/policies/permissions.js:97:3)
at async /srv/app/node_modules/strapi-utils/lib/policy.js:52:5
[2021-02-07T21:01:35.334Z] debug POST /upload (564 ms) 500
The image is successfully uploaded however it is not associated with the entry. What do I need to change to associate the image with the entry?
change "page_rows" to "page_row"
it helped me
formatEntryUpload ( file, "page_rows", id, "images", "users-permissions") =>
formatEntryUpload ( file, "page_row", id, "images", "users-permissions");
Hello guys when i'm running this code in ReactJS
const callApi = async () => {
const response = await axios.get('http://api.openweathermap.org/data/2.5/weather?q=London&units=metric&appid=mykey');
setWeather(response)
}
i can get to console.log(weather.data) but when i try to get console.log(weather.data.main)
i get this error TypeError: Cannot read property 'main' of undefined i tried to parse that data to JSON but that didnt work either.
Here you can see that this object has this property:
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 804,
"main": "Clouds",
"description": "overcast clouds",
"icon": "04n"
}
],
"base": "stations",
"main": {
"temp": 12.43,
"feels_like": 7.81,
"temp_min": 11.67,
"temp_max": 13,
"pressure": 1010,
"humidity": 62
},
.....other items
}
Thank you for all answers.
Sometimes during the first render data isn't defined yet so use:
console.log(weather.data?.main)
and works like a if(data)
I'm a bit stumped on this problem I encountered trying to render the data from an API. Weird thing is I successfully fetched the data and I can render the values of properties in the array but the moment it becomes a nested property within an array it returns undefined. Do you by any chance know why?
location[0] + '&lon=' +
location[1] + '&APPID=8e6150cf719d58fc8062d507eaba92c0'
const [data, loading] = useFetch(url);
console.log(data.main.temp) // returns undefined
console.log(data.name) // logs name
The useFetch() is the following:
useEffect(() => {
async function fetchUrl() {
const response = await fetch(url);
const json = await response.json();
setData(json);
setLoading(false);
}
fetchUrl();
}, [url]);
return [data, loading];
}
export { useFetch };
The error message is:
TypeError: Cannot read property 'temp' of undefined
Data fetched looks like this:
{
"coord": {
"lon": 2.18,
"lat": 41.42
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}
],
"base": "stations",
"main": {
"temp": 293.81,
"pressure": 1013,
"humidity": 77,
"temp_min": 292.04,
"temp_max": 294.82
},
"visibility": 10000,
"wind": {
"speed": 2.6,
"deg": 120
},
"clouds": {
"all": 0
},
"dt": 1561061585,
"sys": {
"type": 1,
"id": 6414,
"message": 0.0074,
"country": "ES",
"sunrise": 1561004254,
"sunset": 1561058875
},
"timezone": 7200,
"id": 3124932,
"name": "el Clot",
"cod": 200
}