Skip to content

Commit 73458a8

Browse files
author
James Zetlen
committed
feat(production): loggability and error tolerance
fix(compat): adhere more to fastly behavior in canvas
1 parent 593d19e commit 73458a8

29 files changed

+1032
-584
lines changed

package-lock.json

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"dependencies": {
6565
"accepts": "^1.3.7",
6666
"debug": "^4.1.1",
67+
"mime": "^2.4.4",
6768
"mime-types": "^2.1.25",
6869
"on-headers": "^1.0.2",
6970
"vary": "^1.1.2"

src/lib/errors.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
import { Param, Params } from './imageopto-types';
1+
import { IRequestErrors, Warning } from './imageopto-types';
22

3-
/**
4-
* @hidden
5-
*/
6-
export class FastlyParamError extends Error {
7-
constructor(params: Params, name: Param, customMessage?: string) {
8-
let message = `"${name}" cannot be "${params.get(name)}"`;
9-
if (customMessage) {
10-
message += `: ${customMessage}`;
11-
}
12-
super(message);
13-
Error.captureStackTrace(this, this.constructor);
3+
export default class RequestErrors implements IRequestErrors {
4+
public url: string;
5+
public warnings: Warning[];
6+
constructor(url: string, warnings: Warning[]) {
7+
this.url = url;
8+
this.warnings = warnings;
149
}
15-
}
16-
17-
/**
18-
* @hidden
19-
*/
20-
export class FastlyCompatError extends FastlyParamError {
21-
constructor(params: Params, name: Param, feature: string) {
22-
super(
23-
params,
24-
name,
25-
`Fastly imageopto ${feature} unsupported by node-hastily`
26-
);
10+
public toJSON(): IRequestErrors {
11+
return { url: this.url, warnings: this.warnings };
12+
}
13+
public toString(): string {
14+
return `Processing "${this.url}" produced warnings:${this.warnings.map(
15+
({ type, msg }) => `\n - [${type}]: ${msg}`
16+
)}
17+
`;
2718
}
2819
}

src/lib/fastly-params.spec.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import test from 'ava';
2+
import { mockParams } from './mappers/__testhelpers';
3+
4+
test('quality getter works', t => {
5+
const noQuality = mockParams('');
6+
t.is(noQuality.quality, undefined, 'unset quality is undefined');
7+
t.is(noQuality.quality, undefined, 'cached quality');
8+
t.is(
9+
mockParams('quality=nothing').quality,
10+
undefined,
11+
'NaN quality is undefined'
12+
);
13+
t.is(mockParams('quality=50').quality, 50, 'numeric quality is stored');
14+
});
15+
16+
test('toTaggedValues honors positionals', t => {
17+
t.deepEqual(
18+
mockParams('canvas=a,b,ccee,ddee,feff,eeee').toTaggedValues(
19+
'canvas',
20+
['ay', 'bee'],
21+
['c', 'd', 'e', 'f']
22+
),
23+
{
24+
ay: 'a',
25+
bee: 'b',
26+
c: 'cee',
27+
d: 'dee',
28+
e: 'eee',
29+
f: 'eff'
30+
}
31+
);
32+
});
33+
34+
test('toTaggedValues honors positionals 2 s', t => {
35+
t.deepEqual(
36+
mockParams('canvas=300,300,x90,y10').toTaggedValues(
37+
'canvas',
38+
['width', 'height'],
39+
['x', 'y', 'smart', 'offset-x', 'offset-y']
40+
),
41+
{
42+
height: '300',
43+
width: '300',
44+
x: '90',
45+
y: '10'
46+
}
47+
);
48+
});
49+
50+
test('toTaggedValues does not put named params in positionals', t => {
51+
t.throws(() =>
52+
mockParams('canvas=400,gutter5').toTaggedValues(
53+
'canvas',
54+
['width', 'height'],
55+
['gutter']
56+
)
57+
);
58+
});

0 commit comments

Comments
 (0)