Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I keep getting a 503 from my resource with custom handler #340

Open
jrdn91 opened this issue Nov 13, 2017 · 7 comments
Open

I keep getting a 503 from my resource with custom handler #340

jrdn91 opened this issue Nov 13, 2017 · 7 comments

Comments

@jrdn91
Copy link

jrdn91 commented Nov 13, 2017

I'm trying to make a custom handler that will handle my resource for making a PDF, but I keep getting a 503 in my response

I'm only implementing POST here because that's all I'll be using

"use strict";

var PrintHandler = module.exports = function PrintHandler(config) {
  this._config = config;
};

PrintHandler.prototype.ready = false;

PrintHandler.prototype.initialise = function(resourceConfig) {
  self.ready = true;
};

PrintHandler.prototype.create = function(request, newResource, callback) {
  console.log(newResource);
  return callback(null, {
    message:'hello world'
  });
};

Right now I'm just trying to get it working. Why am I getting this error? If I switch to using a real handler like the mongodb on it works, but just not with a custom handler

@jrdn91
Copy link
Author

jrdn91 commented Nov 13, 2017

I was able to get past this error by doing this ...

let PrintHandler = new printHandler();

jsonApi.define({
  resource: "print",
  handlers: PrintHandler,
...

However now I'm getting a general 500 error, I added a search and find since it was complaining about it and I'm attempting to use the search I am getting a generic 500 error, the detail just says ??

I made sure to specify the search params and added them as a query param in postman

Here is my search function

PrintHandler.prototype.search = function (request, callback) {
  const self = this
  console.log(request.route.query)
  return callback(null, {
    message: 'hello world'
  }, 1)
}

@paparomeo
Copy link
Contributor

Can you show me the full code for your custom handler so I can test it locally?

@jrdn91
Copy link
Author

jrdn91 commented Nov 14, 2017

@paparomeo
Copy link
Contributor

One of the issues you have with your search method is that it needs to return an Array. I'm working on a PR which will make this explicit rather than failing with the generic error. Anyway try to change it to return an array with a single element and you should be able to progress.

@jrdn91
Copy link
Author

jrdn91 commented Nov 19, 2017

PrintHandler.prototype.search = function (request, callback) {
  const self = this
  console.log(request.route.query)
  return callback(null, [{
    message: 'hello world'
  }])
}

I'm getting this output in postman

{
    "jsonapi": {
        "version": "1.0"
    },
    "meta": {},
    "links": {
        "self": "/api/v1/print"
    },
    "data": [],
    "included": []
}

@paparomeo
Copy link
Contributor

Try running the server with DEBUG environment variable set to * (e.g. in bash: DEBUG=* npm start). That should provide you debugging output which will make clearer what the problem is.

@jrdn91
Copy link
Author

jrdn91 commented Nov 20, 2017

I see it's complaining about there not being an id property set.

Is there a way I can specify a route handler through express and break out of these jsonapi requirements for just this one route since it's such a specific usage? I tried grabbing the express server and attaching a route handler after doing the readdirSync but it doesn't seem to be doing anything

var app = jsonApi.getExpressServer();
app.get('/test',function(req,res){
  res.send({
    message: 'hello world'
  })
});

Maybe this isn't possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants