mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 12:30:32 +09:00
chore: capitalize error message
This commit is contained in:
parent
5c4f9959f1
commit
8ecfb3919a
@ -20,7 +20,7 @@ export default async function handler(
|
|||||||
const {query, country} = req.query;
|
const {query, country} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const term = encodeURIComponent(query);
|
const term = encodeURIComponent(query);
|
||||||
|
@ -4,7 +4,11 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
||||||
|
return sendError(res, new Error('Invalid characters'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -14,7 +14,7 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -23,7 +23,7 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
send(res, {availability});
|
send(res, {availability});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'ENODATA' || err.code === 'ENOTFOUND') {
|
if (err.code === 'ENODATA' || err.code === 'ENOTFOUND') {
|
||||||
return res.status(200).json({availability: true});
|
return send(res, {availability: true});
|
||||||
}
|
}
|
||||||
sendError(res, err);
|
sendError(res, err);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -13,6 +13,9 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const availability = response[0].data.domainName ? false : true;
|
const availability = response[0].data.domainName ? false : true;
|
||||||
send(res, {availability});
|
send(res, {availability});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.code === 'ENOTFOUND') {
|
||||||
|
return send(res, {availability: true});
|
||||||
|
}
|
||||||
sendError(res, err);
|
sendError(res, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
query,
|
query,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return sendError(res, new Error('invalid characters'));
|
return sendError(res, new Error('Invalid characters'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -20,6 +20,10 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const availability = response.status === 404;
|
const availability = response.status === 404;
|
||||||
send(res, {availability});
|
send(res, {availability});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err.code);
|
||||||
|
if (err.code === 'ENOTFOUND') {
|
||||||
|
return send(res, {availability: true});
|
||||||
|
}
|
||||||
sendError(res, err);
|
sendError(res, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
||||||
import nodeFetch from 'node-fetch'
|
import nodeFetch from 'node-fetch';
|
||||||
|
|
||||||
export default async function handler(req: NowRequest, res: NowResponse) {
|
export default async function handler(req: NowRequest, res: NowResponse) {
|
||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
||||||
/[^\w-]/.test(
|
return sendError(res, new Error('Invalid characters'));
|
||||||
query,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return sendError(res, new Error('invalid characters'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await nodeFetch(`https://gitlab.com/${query}`, {redirect: 'manual'});
|
const response = await nodeFetch(`https://gitlab.com/${query}`, {
|
||||||
|
redirect: 'manual',
|
||||||
|
});
|
||||||
const availability = response.status === 302;
|
const availability = response.status === 302;
|
||||||
send(res, {availability});
|
send(res, {availability});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -4,7 +4,11 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
||||||
|
return sendError(res, new Error('Invalid characters'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -5,13 +5,16 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const availability = await npmName(`@${query}`);
|
const availability = await npmName(`@${query}`);
|
||||||
send(res, {availability});
|
send(res, {availability});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.code === 'ENOTFOUND') {
|
||||||
|
return send(res, {availability: true});
|
||||||
|
}
|
||||||
sendError(res, err);
|
sendError(res, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -9,7 +9,7 @@ export default async function handler(
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const encodedQuery = encodeURIComponent(
|
const encodedQuery = encodeURIComponent(
|
||||||
|
@ -4,7 +4,11 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
||||||
|
return sendError(res, new Error('Invalid characters'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -14,10 +18,6 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const availability = response.status !== 200;
|
const availability = response.status !== 200;
|
||||||
send(res, {availability});
|
send(res, {availability});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'ENOTFOUND') {
|
|
||||||
send(res, {availability: true});
|
|
||||||
} else {
|
|
||||||
sendError(res, err);
|
sendError(res, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -4,7 +4,11 @@ export default async function handler(req: NowRequest, res: NowResponse) {
|
|||||||
const {query} = req.query;
|
const {query} = req.query;
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return sendError(res, new Error('no query given'));
|
return sendError(res, new Error('No query given'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
||||||
|
return sendError(res, new Error('Invalid characters'));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user