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

Add ResponseSizeTooLarge Error #3020

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@ export class MissingScopesError extends Error {
}
}

/**
* An error that will be thrown by {@link Fetcher.fetch} when the response body from the external system
* exceeds packs platform limits
*
* This error can be caught and retried by requesting less data from the external system through
* a smaller page size or omitting large fields.
*
* @hidden
*/
export class ResponseSizeTooLargeError extends Error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to try to include any information here that would help the pack code understand the size of the response either in absolute terms or relative to the maximum allowed?

I don't think we can do that 100% of the time (like maybe if a server returns data with chunked response encoding we could see that the data is too large, but we don't necessarily know how large it would have been) so I'm fine with making this error vague for now and leaving the option to add more detail in the future if we think it's useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could certainly put an estimate of the response size + the limit that was violated. Not sure if they bytes limit is that helpful but could be worth a shot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a blocking comment, so if you have a plan to use this that doesn't depend on getting numbers back in the response I'm fine with that as long we there's no API structure objections from Patrick or Eric

(One thing I thought about re: API was whether this could be expressed as a StatusCodeError, but HTTP only seems to have an official status code for request to big, but not standard error code for response would be too big)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also do not want to confuse StatusCodeErrors and errors that are imposed by Coda. I think that could be potentially confusing to the consumer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestTooLarge would also be good to add at some point, but doesn't need to block this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add as needed. Starting with this. Once this is going in a real pack can add the other error as well will be very similar

/**
* The name of the error, for identification purposes.
*/
override name: string = 'ResponseSizeTooLargeError';

/** @hidden */
constructor(message?: string | undefined) {
super(message || 'Response size too large');
}

/** Returns if the error is an instance of ResponseSizeTooLargeError. Note that `instanceof` may not work. */
static isResponseSizeTooLargeError(err: any): err is ResponseSizeTooLargeError {
return 'name' in err && err.name === ResponseSizeTooLargeError.name;
}
}

/**
* A map of named property options methods for a particular sync table. The names need to match
* the values stored in the object schema. For the name, we use the property's name so that
Expand Down
19 changes: 18 additions & 1 deletion bundles/thunk_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5911,6 +5911,22 @@ module.exports = (() => {
};
__name(_MissingScopesError, "MissingScopesError");
var MissingScopesError = _MissingScopesError;
var _ResponseSizeTooLargeError = class _ResponseSizeTooLargeError extends Error {
/** @hidden */
constructor(message) {
super(message || "Response size too large");
/**
* The name of the error, for identification purposes.
*/
this.name = "ResponseSizeTooLargeError";
}
/** Returns if the error is an instance of ResponseSizeTooLargeError. Note that `instanceof` may not work. */
static isResponseSizeTooLargeError(err) {
return "name" in err && err.name === _ResponseSizeTooLargeError.name;
}
};
__name(_ResponseSizeTooLargeError, "ResponseSizeTooLargeError");
var ResponseSizeTooLargeError = _ResponseSizeTooLargeError;
function isDynamicSyncTable(syncTable) {
return "isDynamic" in syncTable;
}
Expand Down Expand Up @@ -6164,7 +6180,8 @@ module.exports = (() => {
var recognizableCodaErrorClasses2 = [
// StatusCodeError doesn't have the new StatusCodeError(message) constructor but it's okay.
StatusCodeError,
MissingScopesError
MissingScopesError,
ResponseSizeTooLargeError
];
function fixUncopyableTypes(val, pathPrefix, postTransforms, depth = 0) {
if (depth >= MaxTraverseDepth) {
Expand Down
19 changes: 19 additions & 0 deletions dist/api.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion dist/api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion dist/bundles/thunk_bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion dist/runtime/common/marshaling/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codahq/packs-sdk",
"version": "1.7.9",
"version": "1.7.9-prerelease.1",
"license": "MIT",
"workspaces": [
"dev/eslint"
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/marshaling/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {CodaMarshalerType} from './constants';
import {MarshalingInjectedKeys} from './constants';
import {MissingScopesError} from '../../../api';
import {ResponseSizeTooLargeError} from '../../../api';
import {StatusCodeError} from '../../../api';
import {deserialize} from './serializer';
import {format} from 'util';
Expand Down Expand Up @@ -66,6 +67,7 @@ const recognizableCodaErrorClasses: ErrorConstructor[] = [
// StatusCodeError doesn't have the new StatusCodeError(message) constructor but it's okay.
StatusCodeError as any,
MissingScopesError as any,
ResponseSizeTooLargeError as any,
];

// pathPrefix can be temporarily modified, but needs to be restored to its original value
Expand Down