Skip to content

Commit

Permalink
update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Oct 23, 2023
1 parent b34cee3 commit c5c243e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"dependencies": {
"@grpc/grpc-js": "1.8.1",
"@nitric/grpc-error-status": "^0.0.1",
"@nitric/grpc-error-status": "^0.0.2",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/exporter-trace-otlp-http": "^0.36.1",
"@opentelemetry/instrumentation": "^0.36.1",
Expand Down
2 changes: 1 addition & 1 deletion src/api/documents/v0/document-ref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('Document Ref Tests', () => {
const testNestedAgain = () => nestedCollection.collection('nested-again');

expect(testNestedAgain).toThrow(
new InvalidArgumentError('Maximum collection depth 1 exceeded')
new Error('Maximum collection depth 1 exceeded')
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/documents/v0/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ describe('Query Tests', () => {

q.pagingFrom('test' as any);

await expect(q.fetch()).rejects.toStrictEqual(
new InvalidArgumentError('Invalid paging token provided!')
await expect(q.fetch()).rejects.toEqual(
new Error('Invalid paging token provided!')
);
});
});
Expand Down
14 changes: 11 additions & 3 deletions src/api/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,21 @@ export const fromGrpcError = (error: ServiceError): Error => {

const errorStatus = parse(error);

const [details] = errorStatus.parseDetails(ErrorDetails);
let errorDetails: ErrorDetails | undefined = undefined;

if (errorStatus) {
const allDetails = errorStatus.parseDetails(ErrorDetails);

if (allDetails.length > 0) {
errorDetails = allDetails[0];
}
}

if (construct) {
return new construct(error.message, details);
return new construct(error.message, errorDetails);
}

return new UnknownError(error.message, details);
return new UnknownError(error.message, errorDetails);
};

// Re-export errors
Expand Down
11 changes: 7 additions & 4 deletions src/api/errors/plugin-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ import { ErrorDetails } from '@nitric/sdk/gen/proto/error/v1/error_pb';
* Operation was cancelled (typically occurs client side)
*/
export class NitricPluginError extends Error {
constructor(message: string, details: ErrorDetails) {
const errorMessage = `${message};
constructor(message: string, details?: ErrorDetails) {

let errorMessage = message;
if (details) {
errorMessage = `${message};
Nitric Plugin Error: ${details.getScope().getPlugin()}.${details
.getScope()
.getService()}
Message: ${details.getMessage()}
Caused By: ${details.getCause()}
`;
Caused By: ${details.getCause()}`;
}

super(errorMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/errors/unimplemented.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { NitricPluginError } from './plugin-error';
* The requested operation was not implemented for the service provider.
*/
export class UnimplementedError extends NitricPluginError {
constructor(message: string, details: ErrorDetails) {
constructor(message: string, details?: ErrorDetails) {
super(message, details);
Object.setPrototypeOf(this, UnimplementedError.prototype);
}
Expand Down
1 change: 0 additions & 1 deletion src/resources/websocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ResourceServiceClient } from '@nitric/api/proto/resource/v1/resource_gr
import { UnimplementedError } from '../api/errors';
import { websocket } from '.';
import { ResourceDeclareResponse } from '@nitric/api/proto/resource/v1/resource_pb';
import * as faas from '../faas/index';

jest.mock('../faas/index');

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@
semver "^7.3.5"
tar "^6.1.11"

"@nitric/grpc-error-status@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@nitric/grpc-error-status/-/grpc-error-status-0.0.1.tgz#317ca345dc4f99b3a8ff98561a22465aae9acda2"
integrity sha512-4Z5TCCYBtfM+1UXq8b2BCDdc3Y03OZ7Y9gYMoBo3OcxxItKje1pu9kw/xq+d4gEjl/Xq0eLshtsI/Xfx+cJLSw==
"@nitric/grpc-error-status@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@nitric/grpc-error-status/-/grpc-error-status-0.0.2.tgz#a8f6866f968468c9585df0868a4a0754efb0973a"
integrity sha512-LDeUZ0zr+r/aYQs/6Iq7jw0VhQuxCCDfX7oIlaVfk719CEEmvGrOPRv0B1d192ZY8+lMIWYocoGGexL7+CF6eA==
dependencies:
google-protobuf "^3.14.0"

Expand Down

0 comments on commit c5c243e

Please sign in to comment.