Skip to content

Commit

Permalink
Add timeout error
Browse files Browse the repository at this point in the history
  • Loading branch information
krasun committed Apr 30, 2024
0 parents commit c46f088
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 17.x, 18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

# Build
public/css/main.css

# Coverage reports
coverage

# API keys and secrets
.env

# Dependency directory
node_modules
bower_components

# Editors
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
dist/**/*

# ignore yarn.lock
yarn.lock
38 changes: 38 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

# Build
public/css/main.css

# Coverage reports
coverage

# API keys and secrets
.env

# Dependency directory
node_modules
bower_components

# Editors
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db

# ignore yarn.lock
yarn.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 ScreenshotOne.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# validations

[![Build](https://github.com/screenshotone/validations/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/screenshotone/validations/actions/workflows/build.yml)
[![NPM package](https://img.shields.io/npm/v/screenshotone-validations.svg?branch=main)](https://www.npmjs.com/package/screenshotone-validations)

A set of validation schemes for the [Screenshot API](https://screenshotone.com/) requests.

## Installation

```shell
npm install screenshotone-validations --save
```

## Build and publish (a manual for developers)

To build and publish the library:

1. Bump the version property in the `package.json` file.
2. Run `npm run prepare`.
3. Run `npm publish`.

## License

`screenshotone/validations` is released under [the MIT license](LICENSE).
50 changes: 50 additions & 0 deletions package-lock.json

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

41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "screenshotone-errors",
"homepage": "https://screenshotone.com",
"version": "1.0.0",
"description": "Errors produced by the ScreenshotOne API.",
"repository": {
"type": "git",
"url": "git+https://github.com/screenshotone/errors.git"
},
"keywords": [
"screenshot",
"phantom",
"phantomjs",
"screenshots",
"webkit",
"webkit2png",
"url2png",
"headless",
"chrome",
"chromium",
"blink",
"render"
],
"author": "Dmytro Krasun",
"license": "MIT",
"bugs": {
"email": "[email protected]",
"url": "https://github.com/screenshotone/errors/issues"
},
"main": "dist/main.js",
"types": "dist/@types/main.d.ts",
"devDependencies": {
"@types/node": "^17.0.40",
"typescript": "^4.7.3"
},
"scripts": {
"test": "jest",
"build": "./node_modules/typescript/bin/tsc",
"prepare": "npm run build"
}
}
24 changes: 24 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
enum ErrorCode {
Timeout = "timeout",
}

interface APIError {
HTTPStatusCode: number;
ErrorCode: string;
ErrorDescription: string;
ErrorDocumentationLink: string;
}

const Errors: Record<ErrorCode, APIError> = {
[ErrorCode.Timeout]: {
HTTPStatusCode: 500,
ErrorCode: "timeout_error",
ErrorDescription:
"The screenshot couldn't be taken within the specified timeout. Either the site doesn't respond quickly, or rendering takes longer than expected. Play with the `timeout` or the `navigation_timeout` options or reach the support for the investigation.",
ErrorDocumentationLink: "https://screenshotone.com/docs/errors/",
},
};

export function APIError(code: ErrorCode) {
return Errors[code];
}
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"lib": [
"es2021"
],
"module": "commonjs",
"target": "es2021",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist",
"declarationDir": "dist/@types",
"declaration": true,
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}

0 comments on commit c46f088

Please sign in to comment.