Giter VIP home page Giter VIP logo

moleculer-http-client's Issues

ServiceNotFoundError: Service 'http.get' is not found.

I am using the Moleculer project template. I have install moleculer-http-client. And I have added the httpClient to the setting. But I got the error "ServiceNotFoundError: Service 'http.get' is not found."

const HTTPClientService = require("moleculer-http-client");


module.exports = {
	name: "greeter",
	mixins: [HTTPClientService],

	settings: {
		// HTTP client settings
		httpClient: {
			// Boolean value indicating whether request should be logged or not
			logging: true,

			// // Log request function
			// logOutgoingRequest: logOutgoingRequest,

			// // Log response function
			// logIncomingResponse: logIncomingResponse,

			// Format the Response
			responseFormatter: "body", // one of "body", "headers", "status", "raw"

			// Format the Errors
			// errorFormatter: errorFormatter,

			// Got Client options
			defaultOptions: {
				// Put here any Got available option that can be used to extend Got client
			}
		}
	},

	/**
	 * Dependencies
	 */
	dependencies: [],

	/**
	 * Actions
	 */
	actions: {

		/**
		 * Say a 'Hello' action.
		 *
		 * @returns
		 */
		hello: {
			rest: {
				method: "GET",
				path: "/hello"
			},
			async handler() {
				this.broker.call('http.get', {
					url: 'https://postman-echo.com/get?foo1=bar1&foo2=bar2'
				});
				return "Hello Moleculer";
			}
		},
	},
};

`

Converting circular structure to JSON

Hi,
I need to get body and headers from response. So, I put:

httpClient: {
logging: true,
responseFormatter: "raw",
errorFormatter: httpError,
},

But, in this format is creating a circular reference, causing an error in json serializer:
"Converting circular structure to JSON --> starting at object with constructor 'TLSSocket' | property '_httpMessage' -> object with constructor 'ClientRequest' --- property 'socket' closes the circle"

"TypeError: Converting circular structure to JSON
--> starting at object with constructor 'TLSSocket'
| property '_httpMessage' -> object with constructor 'ClientRequest'
--- property 'socket' closes the circle
at JSON.stringify ()
at JSONSerializer.serialize (.../add-tools-http-api/node_modules/moleculer/src/serializers/json.js:35:27)
at RedisTransporter.serialize (.../add-tools-http-api/node_modules/moleculer/src/transporters/base.js:347:33)
at RedisTransporter.publish (.../add-tools-http-api/node_modules/moleculer/src/transporters/base.js:190:21)
at RedisTransporter.prepublish (.../add-tools-http-api/node_modules/moleculer/src/transporters/base.js:333:15)
at Transit.publish (.../add-tools-http-api/node_modules/moleculer/src/transit.js:1372:18)
at Transit.sendResponse (.../add-tools-http-api/node_modules/moleculer/src/transit.js:1166:15)
at .../add-tools-http-api/node_modules/moleculer/src/transit.js:507:23
at processTicksAndRejections (node:internal/process/task_queues:96:5)"

Thanks for any help

Error in console after adding moleculer-http-client as mixins

  1. require const HTTPClientService = require("moleculer-http-client");
  2. mixins: [HTTPClientService], // this line throws an error in console
  3. Run npm run dev

--

Result :

Request error! TypeError : Converting circular structure to JSON
    --> starting at object with constructor 'ServiceBroker'
    |     property 'services' -> object with constructor 'Array'
    |     index 0 -> object with constructor 'Service'
    --- property 'broker' closes the circle
 TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'ServiceBroker'
    |     property 'services' -> object with constructor 'Array'
    |     index 0 -> object with constructor 'Service'
    --- property 'broker' closes the circle
    at JSON.stringify (<anonymous>)
    at Service.encodeResponse (/Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:649:16)
    at Service.sendResponse (/Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:749:18)
    at Service.callAction (/Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:625:10)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async /Volumes/Boskysoft/work-hdd/recrutiment-smart/play/nodejs/moleculer-js/http-client/node_modules/moleculer-web/src/index.js:460:21

/API: <= 500 GET /api/~node/services?withActions=true [+15.368 ms]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.