Skip to content

Commit 7b6e866

Browse files
committed
fix: Minor fixes
1 parent b0faa53 commit 7b6e866

5 files changed

Lines changed: 16 additions & 24 deletions

File tree

packages/uma/src/errors/NeedInfoError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ export class NeedInfoError extends ForbiddenHttpError {
3131
this.ticket = ticket;
3232
this.additionalParams = additionalParams;
3333
}
34+
35+
public static isInstance(error: unknown): error is NeedInfoError {
36+
return ForbiddenHttpError.isInstance(error) && typeof (error as NeedInfoError).ticket === 'string';
37+
}
3438
}

packages/uma/src/routes/ResourceRegistration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ResourceRegistrationRequestHandler extends HttpHandler {
5757
reType(body, ResourceDescription);
5858
} catch (e) {
5959
this.logger.warn(`Syntax error: ${createErrorMessage(e)}, ${body}`);
60-
this.error(BadRequestHttpError, `Request has bad syntax${e instanceof Error ? ': ' + e.message : ''}`)
60+
this.error(BadRequestHttpError, `Request has bad syntax: ${createErrorMessage(e)}`)
6161
}
6262

6363
const resource = randomUUID();

packages/uma/src/routes/Ticket.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,11 @@ export class TicketRequestHandler extends HttpHandler {
3535
this.logger.info(`Received permission registration request.`);
3636
if (!await verifyRequest(request)) throw new UnauthorizedHttpError();
3737

38-
if (!request.body || !Array.isArray(request.body)) {
39-
this.error(BadRequestHttpError, 'Request body must be a JSON array.');
40-
}
41-
4238
try {
4339
reType(request.body, array(Permission));
4440
} catch (e) {
45-
this.logger.debug(`Syntax error: ${createErrorMessage(e)}, ${request.body}`);
46-
e instanceof Error
47-
? this.error(BadRequestHttpError, 'Request has bad syntax: ' + e.message)
48-
: this.error(BadRequestHttpError, 'Request has bad syntax');
41+
this.logger.warn(`Syntax error: ${createErrorMessage(e)}, ${request.body}`);
42+
throw new BadRequestHttpError(`Request has bad syntax: ${createErrorMessage(e)}`);
4943
}
5044

5145
const ticket = await this.ticketingStrategy.initializeTicket(request.body);
@@ -61,15 +55,4 @@ export class TicketRequestHandler extends HttpHandler {
6155
body: { ticket: id },
6256
};
6357
}
64-
65-
/**
66-
* Logs and throws an error
67-
*
68-
* @param {ErrorConstructor} constructor - the error constructor
69-
* @param {string} message - the error message
70-
*/
71-
private error(constructor: ErrorConstructor, message: string): never {
72-
this.logger.warn(message);
73-
throw new constructor(message);
74-
}
7558
}

packages/uma/src/routes/Token.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export class TokenRequestHandler extends HttpHandler {
4141
body: tokenResponse
4242
};
4343
} catch (e) {
44-
if (ForbiddenHttpError.isInstance(e)) return ({
44+
if (NeedInfoError.isInstance(e)) return ({
4545
status: 403,
4646
body: {
47-
ticket: (e as NeedInfoError).ticket,
48-
...(e as NeedInfoError).additionalParams
47+
ticket: e.ticket,
48+
...e.additionalParams
4949
}
5050
});
5151
throw e; // TODO: distinguish other errors

packages/uma/src/util/http/server/NodeHttpRequestResponseHandler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export class NodeHttpRequestResponseHandler extends NodeHttpStreamsHandler {
6868

6969
const context: HttpHandlerContext<Buffer> = { request: httpHandlerRequest };
7070

71-
this.logger.info(`Domestic request: ${JSON.stringify({ eventType: 'domestic_request', context })}`);
71+
this.logger.info(`Domestic request: ${JSON.stringify({ eventType: 'domestic_request', context: {
72+
request: {
73+
...context.request,
74+
...context.request.body && { body: context.request.body.toString() }
75+
}
76+
} })}`);
7277

7378
let response = await this.httpHandler.handleSafe(context);
7479

0 commit comments

Comments
 (0)