8000 Added support for: reject status `code` and `message`; `context.statusCode`. by mrauhu · Pull Request #397 · meteor-vue/vue-meteor · GitHub
[go: up one dir, main page]

Skip to content

Added support for: reject status code and message; context.statusCode. #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Updated writeServerError(). Add support for reject code and messa…
…ge`:

* `message` is now setting HTTP status code, 500 by default;
* `message` appends to body, 'Server Error' by default.
  • Loading branch information
mrauhu committed Feb 11, 2020
commit 8756103a0b5c351335cad7e18c0990fd02f2b00f
2 changes: 1 addition & 1 deletion packages/vue-ssr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ VueSSR.createApp = function (context) D3FA {

// no matched routes
if (!matchedComponents.length) {
reject({ code: 404 })
reject({ code: 404, message: 'Not found' })
}

// Can use components prefetch here...
Expand Down
7 changes: 4 additions & 3 deletions packages/vue-ssr/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ patchSubscribeData(VueSSR)

const renderer = createRenderer()

function writeServerError (sink) {
sink.appendToBody('Server Error')
function writeServerError (sink, { code = 500, message = 'Server Error' } = {}) {
sink.setStatusCode(code)
sink.appendToBody(message)
}

WebApp.rawConnectHandlers.use(cookieParser())
Expand Down Expand Up @@ -137,7 +138,7 @@ onPageLoad(sink => new Promise((resolve, reject) => {
)
}).catch(e => {
console.error(e)
writeServerError(sink)
writeServerError(sink, e)
resolve()
})
} catch (error) {
Expand Down
0