feathersjs-ecosystem / socketio

[MOVED] The Feathers Socket.io websocket transport plugin
https://github.com/feathersjs/feathers
MIT License
37 stars 14 forks source link

Client should convert error objects to feathers-errors #30

Closed daffl closed 8 years ago

v1p commented 7 years ago

@daffl Hey David! Just curious if this bug was actually solved.

I am using feathers auk release, have a generated backend service i.e. default generated app. the middleware/index.js is configured as documented :

'use strict';

const handler = require('feathers-errors/handler');
const notFound = require('./not-found-handler');
const logger = require('./logger');

module.exports = function() {
  // Add your custom middleware here. Remember, that
  // just like Express the order matters, so error
  // handling middleware should go last.
  const app = this;

  app.use(notFound());
  app.use(logger(app));
  app.use(handler());
};

In the client I am working with React & have configured feathers-client as documented :


import io from 'socket.io-client';
import feathers from 'feathers-client';
import rx from 'feathers-reactive';
import RxJS from 'rxjs';

const apiHost = "ws://localhost:3030";

const socket = io(apiHost);
export const app = feathers()
  .configure(feathers.socketio(socket))
  .configure(rx(RxJS))
  .configure(feathers.hooks())
  .configure(feathers.authentication({ storage: window.localStorage }));

This is how I am calling a service


export function signup(app, email, password) {
  const users = app.service('users');
  return users.create({email, password})
    .then((data, err) => data)
    .catch((err) => {
      console.log(err);
      return;
    });
}

The error is never a feathers-errors object. It's always a stacktrace, saying validation failed & I have gone over the documentation looking for any specific error handling configuration with respect to socketio.

Please suggest if I am missing something obvious to make it work.

daffl commented 7 years ago

It should be. Error conversion is happening i https://github.com/feathersjs/feathers-socket-commons/blob/master/src/client.js#L77 using https://github.com/feathersjs/feathers-errors/blob/master/src/index.js#L206. How do you know it is not a feathers-errors Error object? It normally doesn't give much away by just using console.log, you will have to call err.toJSON to see all properties.

v1p commented 7 years ago

@daffl My bad. Thanks for the info, I guess I was hitting some other problem when I was trying to access err.errors & it was throwing undefined, but might for a different reason altogether