-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: access-api handling store/info for space not in db returns failure with name #391
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,11 @@ export function service(ctx) { | |
info: Server.provide(Space.info, async ({ capability, invocation }) => { | ||
const results = await ctx.models.spaces.get(capability.with) | ||
if (!results) { | ||
return new Failure('Space not found.') | ||
return { | ||
error: true, | ||
status: 404, | ||
message: 'Space not found.', | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably should start a error.js file like this https://github.com/web3-storage/ucanto/blob/main/packages/validator/src/error.js and a error.ts for error types in the client There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is gonna return a http 200 so i dont think we need the status in there, just a normal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this service could be invoked via non-http transport The status is in there as a reliable machine-readable indication of what kind of error happened. I don't think we should use just a specific 'message' value as the only discriminant of this error case because doing that would make it so that changing the error message string would be a backward-incompatible change from the perspective of any client trying to detect this error case. I'm intentionally trying to add a specific non- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exactly, non-http transport should not need to understand http codes. For errors IMO either use the name as the identifier or a code nodejs style // similar to ucanto
if(error.name === 'SpaceNotFound'){}
// similar to nodejs
class SpaceNotFoundError{}
SpaceNotFoundError.code = 'ERR_SPACE_NOT_FOUND'
if(error.code === SpaceNotFoundError.code) {} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hugomrdias Thanks, when I first responded I missed that you were encouraging a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated [here] to not have a |
||
} | ||
return results | ||
}), | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -60,6 +60,13 @@ export interface SpaceTableMetadata { | |||||||||
agent: AgentMeta | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Indicates failure executing ability that requires access to a space that cannot be found by the handler | ||||||||||
*/ | ||||||||||
export type SpaceNotFoundFailure = Failure & { | ||||||||||
status: 404 | ||||||||||
gobengo marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I would say ☝️, which is I think more accurate than not found. If we want to be future compatible I would go as far as do this instead.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it's worth I don't mind There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got rid of |
||||||||||
} | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe create a new errors.ts file exported from types.ts with something like https://github.com/web3-storage/ucanto/blob/main/packages/interface/src/capability.ts#L413-L416 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the failure type to an |
||||||||||
/** | ||||||||||
* Access api service definition type | ||||||||||
*/ | ||||||||||
|
@@ -73,7 +80,11 @@ export interface Service { | |||||||||
redeem: ServiceMethod<VoucherRedeem, void, Failure> | ||||||||||
} | ||||||||||
space: { | ||||||||||
info: ServiceMethod<SpaceInfo, Selectable<SpaceTable>, Failure> | ||||||||||
info: ServiceMethod< | ||||||||||
SpaceInfo, | ||||||||||
Selectable<SpaceTable>, | ||||||||||
Failure | SpaceNotFoundFailure | ||||||||||
> | ||||||||||
'recover-validation': ServiceMethod< | ||||||||||
SpaceRecoverValidation, | ||||||||||
EncodedDelegation<[SpaceRecover]> | undefined, | ||||||||||
|
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.
I would for something more descriptive with an actionable feedback
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.
I agree it would be good to have actionable feedback in the error message. I defer to @hugomrdias on whether this is the best advice to give, as changing the message here would also require a change the tested behavior, and would prefer to have that change be in separate PR if needed.