-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add support for declaring status code defaults and custom http headers #218
Conversation
e0dc34b
to
730017d
Compare
test please |
@@ -359,7 +359,9 @@ RestAdapter.errorHandler = function(options) { | |||
err.status = err.statusCode = 500; | |||
} | |||
|
|||
res.statusCode = err.statusCode || err.status || 500; | |||
if (res.statusCode === undefined || res.statusCode === 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about other 2xx status codes, like 204 No Content? I am proposing to rewrite the condition to res.statusCode === undefined || res.statusCode < 400
I am not sure if it's a good idea to add a constant var method = givenSharedStaticMethod(
function fn(cb) {
var err = new Error('test error');
err.statusCode = 400;
cb(err);
},
{
http: { status: 201, errorStatus: 508 }
}
);
json(method.url)
.expect(400, done); |
Awesome stuff! It seems to me that passing |
Well we need some way of declaring the status code for a specific result (eg. when the result is ok send this status, when the result is an error send this status). I think the |
730017d
to
04314ed
Compare
04314ed
to
e5d71a7
Compare
@ritch Remote methods' accepts & returns are documented here: http://apidocs.strongloop.com/strong-remoting/#sharedmethod (in source file https://github.com/strongloop/strong-remoting/blob/master/lib/shared-method.js). It might be best for you to add docs, since I'm not familiar with this PR. But if you want me to do it, please just open a doc issue. |
var defaultStatus = this.method.http.status; | ||
|
||
if (defaultStatus) { | ||
res.status(defaultStatus); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check that res.statusCode === undefined || res.statusCode === 200
before applying defaultStatus
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the check...
The code LGTM, although I left one comment/question for your consideration. Please make sure the CI builds are green before landing this patch. |
e5d71a7
to
730017d
Compare
86f39f2
to
e5d71a7
Compare
74d3a75
to
f01b8a6
Compare
Add support for declaring status code defaults
I'm having a use case with long video processing, sometimes the video is ready (status code 200) or processing (202). You can get the detailed status on a specific method that returns a status 201 if the processing has finished with the URI on where to get it. So far I'm setting the status code through What has been proposed so far (setting static return status) doesn't work in my use case as I can return 200 or 202. I'm looking for the best way to return non-error status codes. I guess I could go into the ctx.res and manually set this but that feels so wrong. What should I do ? |
@auguster Your method should have a callback argument that's annotated with strong-remoting/test/rest.test.js Lines 2052 to 2095 in 4ef9baa
|
@bajtos I will try that, thanks. |
/to @bajtos
/cc @raymondfeng @dashby3000
This adds a few new features:
status
anderrorStatus
code in yourmethod.http
optionsreturns.http.target
status
sets theres.statusCode
to the provided valueheader
sets thereturns.header
orreturns.arg
named header to the valuereturns: {arg: 'length', {http: {target: 'header', header: 'Content-Length'}}}
Connect to #186