Browse Source

Improve javascript error handling.

pull/572/head
Sebastian 5 years ago
parent
commit
df2e4b72d3
  1. 8
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs
  3. 1
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs
  4. 9
      backend/src/Squidex.Infrastructure/UsageTracking/ApiStatsSummary.cs
  5. 9
      backend/src/Squidex.Infrastructure/UsageTracking/ApiUsageTracker.cs
  6. 12
      backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/CallsUsageDtoDto.cs
  7. 11
      backend/tests/Squidex.Infrastructure.Tests/UsageTracking/ApiUsageTrackerTests.cs
  8. 4
      frontend/app/features/dashboard/pages/cards/api-calls-summary-card.component.html
  9. 4
      frontend/app/features/dashboard/pages/cards/api-calls-summary-card.component.ts
  10. 4
      frontend/app/features/dashboard/pages/cards/api-traffic-summary-card.component.html
  11. 4
      frontend/app/features/dashboard/pages/cards/api-traffic-summary-card.component.ts
  12. 2
      frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts
  13. 4
      frontend/app/shared/services/usages.service.spec.ts
  14. 4
      frontend/app/shared/services/usages.service.ts

8
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs

@ -184,11 +184,15 @@ namespace Squidex.Domain.Apps.Core.Scripting
}
catch (JavaScriptException ex)
{
throw new ValidationException(T.Get("common.jsError", new { error = ex.Message }));
throw new ValidationException(T.Get("common.jsError", new { message = ex.Message }));
}
catch (ParserException ex)
{
throw new ValidationException(T.Get("common.jsError", new { error = ex.Message }));
throw new ValidationException(T.Get("common.jsError", new { message = ex.Message }));
}
catch
{
throw new ValidationException(T.Get("common.jsError", new { message = "RuntimeError" }));
}
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs

@ -172,7 +172,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
}
catch (Exception)
{
if (Snapshot.ScheduleJob?.Id == c.JobId)
if (Snapshot.ScheduleJob != null && Snapshot.ScheduleJob.Id == c.JobId)
{
CancelChangeStatus(c);
}

1
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs

@ -69,6 +69,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
return contentRepository.QueryScheduledWithoutDataAsync(now, content =>
{
return Task.CompletedTask;
return Dispatch(async () =>
{
try

9
backend/src/Squidex.Infrastructure/UsageTracking/ApiStatsSummary.cs

@ -13,13 +13,20 @@ namespace Squidex.Infrastructure.UsageTracking
public long TotalBytes { get; }
public long MonthCalls { get; }
public long MonthBytes { get; }
public double AverageElapsedMs { get; }
public ApiStatsSummary(long totalCalls, double averageElapsedMs, long totalBytes)
public ApiStatsSummary(double averageElapsedMs, long totalCalls, long totalBytes, long monthCalls, long monthBytes)
{
TotalCalls = totalCalls;
TotalBytes = totalBytes;
MonthCalls = monthCalls;
MonthBytes = monthBytes;
AverageElapsedMs = averageElapsedMs;
}
}

9
backend/src/Squidex.Infrastructure/UsageTracking/ApiUsageTracker.cs

@ -90,7 +90,14 @@ namespace Squidex.Infrastructure.UsageTracking
var summaryElapsedAvg = CalculateAverage(summaryCalls, summaryElapsed);
var summary = new ApiStatsSummary(summaryCalls, summaryElapsedAvg, summaryBytes);
var monthStats = await usageTracker.GetForMonthAsync(apiKey, DateTime.Today, null);
var summary = new ApiStatsSummary(
summaryElapsedAvg,
summaryCalls,
summaryBytes,
monthStats.GetInt64(CounterTotalCalls),
monthStats.GetInt64(CounterTotalBytes));
return (summary, details);
}

12
backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/CallsUsageDtoDto.cs

@ -27,6 +27,16 @@ namespace Squidex.Areas.Api.Controllers.Statistics.Models
/// </summary>
public long TotalBytes { get; set; }
/// <summary>
/// The total number of API calls this month.
/// </summary>
public long MonthCalls { get; set; }
/// <summary>
/// The total number of bytes transferred this month.
/// </summary>
public long MonthBytes { get; set; }
/// <summary>
/// The amount of calls that will block the app.
/// </summary>
@ -63,6 +73,8 @@ namespace Squidex.Areas.Api.Controllers.Statistics.Models
AllowedCalls = plan.MaxApiCalls,
TotalBytes = summary.TotalBytes,
TotalCalls = summary.TotalCalls,
MonthBytes = summary.MonthBytes,
MonthCalls = summary.MonthCalls,
Details = details.ToDictionary(x => x.Key, x => x.Value.Select(CallsUsagePerDateDto.FromStats).ToArray())
};
}

11
backend/tests/Squidex.Infrastructure.Tests/UsageTracking/ApiUsageTrackerTests.cs

@ -106,6 +106,15 @@ namespace Squidex.Infrastructure.UsageTracking
}
};
var forMonth = new Counters
{
[ApiUsageTracker.CounterTotalCalls] = 120,
[ApiUsageTracker.CounterTotalBytes] = 400
};
A.CallTo(() => usageTracker.GetForMonthAsync($"{key}_API", DateTime.Today, null))
.Returns(forMonth);
A.CallTo(() => usageTracker.QueryAsync($"{key}_API", dateFrom, dateTo))
.Returns(counters);
@ -131,7 +140,7 @@ namespace Squidex.Infrastructure.UsageTracking
}
});
summary.Should().BeEquivalentTo(new ApiStatsSummary(15, 20, 3728));
summary.Should().BeEquivalentTo(new ApiStatsSummary(20, 15, 3728, 120, 400));
}
private static Counters Counters(long calls, long elapsed, long bytes)

4
frontend/app/features/dashboard/pages/cards/api-calls-summary-card.component.html

@ -1,10 +1,10 @@
<div class="card card">
<div class="card-header">{{ 'dashboard.apiCallsSummaryCard' | sqxTranslate }}</div>
<div class="card-body">
<div class="aggregation" *ngIf="callsTotal >= 0">
<div class="aggregation" *ngIf="callsMonth >= 0">
<div class="aggregation-label">{{ 'dashboard.currentMonthLabel' | sqxTranslate }}</div>
<div class="aggregation-value">{{callsTotal | sqxKNumber}}</div>
<div class="aggregation-value">{{callsMonth | sqxKNumber}}</div>
<div class="aggregation-label" *ngIf="callsAllowed > 0">
{{ 'dashboard.apiCallsLimitLabel' | sqxTranslate }}: {{callsAllowed | sqxKNumber}}

4
frontend/app/features/dashboard/pages/cards/api-calls-summary-card.component.ts

@ -24,12 +24,12 @@ export class ApiCallsSummaryCardComponent implements OnChanges {
@Input()
public usage: CallsUsageDto;
public callsTotal = 0;
public callsMonth = 0;
public callsAllowed = 0;
public ngOnChanges() {
if (this.usage) {
this.callsTotal = this.usage.totalCalls;
this.callsMonth = this.usage.monthCalls;
this.callsAllowed = this.usage.allowedCalls;
}
}

4
frontend/app/features/dashboard/pages/cards/api-traffic-summary-card.component.html

@ -1,10 +1,10 @@
<div class="card card">
<div class="card-header">{{ 'dashboard.trafficHeader' | sqxTranslate }}</div>
<div class="card-body">
<div class="aggregation" *ngIf="bytesTotal >= 0">
<div class="aggregation" *ngIf="bytesMonth >= 0">
<div class="aggregation-label">{{ 'dashboard.currentMonthLabel' | sqxTranslate }}</div>
<div class="aggregation-value">{{bytesTotal | sqxFileSize}}</div>
<div class="aggregation-value">{{bytesMonth | sqxFileSize}}</div>
<div class="aggregation-label" *ngIf="bytesAllowed > 0">
{{ 'dashboard.trafficLimitLabel' | sqxTranslate }}: {{bytesAllowed | sqxFileSize}}

4
frontend/app/features/dashboard/pages/cards/api-traffic-summary-card.component.ts

@ -25,12 +25,12 @@ export class ApiTrafficSummaryCardComponent implements OnChanges {
@Input()
public usage: CallsUsageDto;
public bytesTotal = 0;
public bytesMonth = 0;
public bytesAllowed = 0;
public ngOnChanges() {
if (this.usage) {
this.bytesTotal = this.usage.totalBytes;
this.bytesMonth = this.usage.monthBytes;
this.bytesAllowed = this.usage.allowedBytes;
}
}

2
frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts

@ -7,7 +7,7 @@
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { fadeAnimation, FieldDto, hasNoValue$, hasValue$, ModalModel, PatternDto, ResourceOwner, RootFieldDto, StringFieldPropertiesDto, Types, value$, STRING_CONTENT_TYPES } from '@app/shared';
import { fadeAnimation, FieldDto, hasNoValue$, hasValue$, ModalModel, PatternDto, ResourceOwner, RootFieldDto, StringFieldPropertiesDto, STRING_CONTENT_TYPES, Types, value$ } from '@app/shared';
import { Observable } from 'rxjs';
@Component({

4
frontend/app/shared/services/usages.service.spec.ts

@ -46,6 +46,8 @@ describe('UsagesService', () => {
blockingCalls: 200,
totalBytes: 1024,
totalCalls: 40,
monthCalls: 5120,
monthBytes: 256,
averageElapsedMs: 12.4,
details: {
category1: [
@ -66,7 +68,7 @@ describe('UsagesService', () => {
});
expect(usages!).toEqual(
new CallsUsageDto(512, 100, 200, 1024, 40, 12.4, {
new CallsUsageDto(512, 100, 200, 1024, 40, 256, 5120, 12.4, {
category1: [
new CallsUsagePerDateDto(DateTime.parseISO('2017-10-12'), 10, 130, 12.3),
new CallsUsagePerDateDto(DateTime.parseISO('2017-10-13'), 13, 170, 33.3)

4
frontend/app/shared/services/usages.service.ts

@ -18,6 +18,8 @@ export class CallsUsageDto {
public readonly blockingCalls: number,
public readonly totalBytes: number,
public readonly totalCalls: number,
public readonly monthBytes: number,
public readonly monthCalls: number,
public readonly averageElapsedMs: number,
public readonly details: { [category: string]: ReadonlyArray<CallsUsagePerDateDto> }
) {
@ -102,6 +104,8 @@ export class UsagesService {
body.blockingCalls,
body.totalBytes,
body.totalCalls,
body.monthBytes,
body.monthCalls,
body.averageElapsedMs,
details);

Loading…
Cancel
Save